I’m getting a very strange result when I try to use string.trim to remove characters.
I want to remove leading and trailing periods (…) from strings, but my code only removes trailing characters for some reason. Microsoft’s documentation says that the string.trim(char array) method should trim from the start and end of the string.
http://msdn.microsoft.com/en-us/library/zke31k1x.aspx
My code to trim the string is…
mystring=mystring.trim(".")
if the input is “2342….” it gets shortened to “2342” but if the input is “…2342” the output is still “…2342”
I’ve tried defining a character array with 1 member (i.e. “.”), but I get the same result.
I’ve also tried mystring.trimstart(“.”) but it does not work either
I’m pretty confused about why I’m getting this behavior
EDITED/SOLVED:
mystring included two different characters that represent dots (.)
One of the characters in mystring was three dots as an ellipsis (the three together were encoded as a single character with a value of 133). The other was a simple period (value of 46).
This solves the problem:
mystring=mystring.Trim(Chr(133)) 'removes ellipsis
mystring=mystring.Trim(Chr(46)) 'removes periods
I tried it right now:
but result is always 2342.
Are you sure that first char in “…2342” is a “.”? Did you check its ASCII value?
Which framework are you using? I’m using Framework 4.0.
EDITED: try this to get ascii values