How to remove 0 (zero) from start but not from end

how to remove 0 from start but not from end.

Var. GetText = the registered value is 0004560.

I have used Split once to get just number from the string value…
Assign
GetText = Split(GetText,". ")(1)
Answer I got is 0004560.

Now I want to remove the 0 from Left side the Dot from end means the Zero from start but the zero 0 from end I want to keep as its the right value…

Result I want 4560…

can someone help… Thanks

Hi,

Can you try TrimStart method as the following?

"0004560".TrimStart("0"c)

Regards,

no its not working

Hi,

In my environment, it works as the following.

img20211117-4

or if there are some whitespace at the beginning of the string, the following might be better.

strVar.TrimStart().TrimStart("0"c)

Regards,

Hi @Latif

Try out this

out_variable= variable.Replace(“000”,“”)

Thanks,
Robinnavinraj S

Hi @Latif ,

Can you show the result of the different options?
I mean you could also use substring, but the other options (trimstart / replace ) also work.

Can you start with putting the original value between quotes? " 004560" , Like Yoichi said there might be whitespaces there at the beginning.

If al else fails you can invoke code, and then split the original value in chars and decide what you want to keep. Would be a bit of a workaround as I don’t see why the other options should not work.

For Each c As Char In Input
If c.ToString.IsNumeric And newval.Length=0 Then
If c.ToString=“0” Then
Console.WriteLine(“Loosing another 0”)
Else
newval= c.ToString
End If
Else If c.ToString.IsNumeric And newval.Length>0 Then
newval=newval+ c.ToString
Else
Console.WriteLine("What else is in this string? "+c.ToString)
End If
Next

Hi @Latif ,

How about this one?
Convert.ToInt32(“0004560”).ToString
Thanks.

1 Like

i have a number 123456 and I want to add “-” inbetween after 4 number from right side.
Length of number is either 10 or 12 but I want “-” after 4 number from right side…

like 123456-7894
or
like 10123456-7891

can someone help… thanks

HI @Latif

Please use insert string function

str_Input = “123456789”
str_Input.Insert(str_Input.Length-4,“-”) will insert the character “-” 4 characters from right side

Thanks

1 Like

Thanks for the big help.