0

I am currently having a variant variable with string vartype. That specific variable may contain string such as "005" and I would like to change it to "5" (without converting it to a number), if it was a regular string I would have done it like so:

Do While Mid(x,1,1)=0 x = Right(x,Len(x)-1) Loop

But alas, I cannot do it with a variant. Is there a way to use the string functions on the variant \ convert the variant to regular string? if not, is there a different solution?

Shperb
  • 474
  • 7
  • 19

1 Answers1

0

You could cast it to a number and then back to a string again.

strNumber = "005"

If IsNumeric(strNumber) Then
    strNumber = CStr(CLng(strNumber))
End If

The FormatNumber() function also formats a number as a string:

strNumber = "005"

' Reformat the number...
strNumber = FormatNumber(strNumber, 0)
Bond
  • 16,071
  • 6
  • 30
  • 53
  • I do not with to convert the string to a number do to the fact the string can represent a number much greater then 2147483647. – Shperb Aug 20 '14 at 14:23
  • Then use `CDbl` instead of `CLng`. The `FormatNumber` function would still work fine with large numbers, too. How big are these numbers? I just tried `FormatNumber` with a 325-digit number and it worked fine. – Bond Aug 20 '14 at 14:25
  • CDbl did the trick, it wont be over 10^28 so its enough, Thank you very much for your help. – Shperb Aug 20 '14 at 14:31
  • No problem. Glad it worked. Your way would have worked, too, but it's just easier to use the "built-in" methods. – Bond Aug 20 '14 at 14:36