VBA – Insert a dash between odd numbers

In the current article, I will present the way to calculate the number of chars in a string with VBA. The inspiration came from the entry exam forHackBulgaria Programming 101v3. The tasks were given some months ago, so I assume it is OK to publish my solutions for them.

The previous task is resolved with VBA here and there.



You have to implement a function with the following signature – dashInsert(num)

  • The argument num is of type integer.
  • The function should return a string

Insert dashes '-' between each two neighboring odd numbers in num.

Don’t count zero as an odd number.

You can use any language you know.



Here the task took me a little more time. I have used two loops – one to determine the number of dashes to be inserted and one to insert them. Furthermore, a function IsOdd was created, checking whether a digit is odd. Pretty much, it works flawlessly:


And here comes the code:

Enjoy it!

Tagged with: , , ,