Hi all
I need help ignoring zeros at the beginning of a line
Example:
00000005138 → 5138
00001796 → 1796
The number of zeros is always different
And if it started with example: D00001526 to leave also
Hi all
I need help ignoring zeros at the beginning of a line
Example:
00000005138 → 5138
00001796 → 1796
The number of zeros is always different
And if it started with example: D00001526 to leave also
@Aibek_Abubakirov Is your Number to be extracted always 4 Digits ?
If the number —> 00000005138 is your string then simply convert it into Int32 by using CInt(“00000005138”) it’ll automatically eliminate those zeros.
Use this in Try catch… so if string value is “D00001526” then it’ll throw error and you should do nothing in catch, to leave that particular value.
no always different
Converting to Int32 will Remove the Preeding Zeroes . But since you have a Scenarios where the string can start from alphabets - there Convert to string will Fail. Hence we have Put the Conversion in trycatch block - This will Handle the exception without chnaging the source Data.
–
Mukesh
I can’t, because sometimes there is a string
Example D00001526,F000018545 …
ok so, SO you can use try catch there.
Hi.
Did you try using replace of regex?
ex : text.replace(/0/gi,“”)
no, in this case it will not change all zeros?
@Aibek_Abubakirov Check if this Expression works :
System.Text.RegularExpressions.Regex.Match(“D00001526”,“[1-9][0-9]+”).ToString
You can test the expression for all kinds of Data that you have using below link
Oh, I didn’t think about it.
But
If the string contains letters, then it should not do anything with it.
Yes… so use CInt(StringVar) in Try catch… so if string value is “D00001526” then it’ll throw error and you should do nothing in catch, to leave that particular value as it is.
@Aibek_Abubakirov If you don’t want to Consider the numbers with values having Letters at the beginning, then you can use Cint(yourString) as suggested by @mukeshkala and @samir . That Should work
There is a variable that passes document number,
If it contains zeros at the beginning, then it should ignore them.
And if there is a letter in it, then I must skip
You can Put the Conversion in Try catch Block as I suggested above ,Please share issues in that Approach.
Hi,
You can use Information.IsNumeric(yourVariable) to check the string.
Your result will be:
result = IIf(Information.IsNumeric(yourVariable), yourVariable, yourVariable.TrimStart("0"C)
Simply use TrimStart
yourVariable.TrimStart("0"C)
Thank you all very much
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.