I search a example to delete all "0" on the left of a string. Example :
toto as string
toto = "00057.4"
for
toto = "57.4"
this string has not the same number of "0"
thanks
String without 0
Moderators: David Barker, Jerry Messina
This should left justify the string (untested):
Code: Select all
Sub LeftJustifyStr(ByRef pstr As String)
FSR0 = @pstr
FSR1 = @pstr
While POSTINC0 = 48 // "0"
Wend
Dec(FSR0)
Repeat
POSTINC1 = POSTINC0
Until INDF0 = 0
INDF1 = 0
End Sub
In a similar way, I was being driven mad trying to figure out why a number in a string being converted to a decimal using StrToDec kept on getting a wrong answer. It kept coming up with the likes of decimal "253" as a value when I knew darn well the original string had only an ascii "0" (hex 30).
It turned out there was a carriage return after the number!! So I made a function to take out the offending carriage return (hex 0D, or decimal 13). I made a variation of the function above to do it.
This function reads the input string into pItem and puts out the result with pStr. Since it's a function, the contents of pStr is returned. If you want a different character, substitute the "13" for a decimal value of whatever character you want to stop at. The function always reads from left to right in your string.
You call it like this:
[/code]
It turned out there was a carriage return after the number!! So I made a function to take out the offending carriage return (hex 0D, or decimal 13). I made a variation of the function above to do it.
This function reads the input string into pItem and puts out the result with pStr. Since it's a function, the contents of pStr is returned. If you want a different character, substitute the "13" for a decimal value of whatever character you want to stop at. The function always reads from left to right in your string.
Code: Select all
Function RemoveCRFromEnd0fString(ByRef pStr As String, ByRef pItem As String) as boolean
result = False
FSR0 = @pStr
FSR1 = @pItem
Repeat
POSTINC1 = POSTINC0
Until INDF0 = 13
INDF1 = 0
End Function
Code: Select all
RemoveCRFromEnd0fString(original_string, output_corrected_string)