[RESOLVED] trim doesnt work -vba outlook
hey,
does anyone has any idea why trim (StrVar) doesn't remove the spaces in the begining and in the end of the string.
the code is simple:
StrVar = right (Item.Body,50)
StrVar = trim (StrVar)
msgbox StrVar "before" & StrVar & "after"
for the body ending in " 1234 " I still get the same string with all the spaces
I'm sure this is really stupid, but I still can't see how...
thanks,
Re: trim doesnt work -vba outlook
Try using a secondary variable to hold the new trimmed value.
VB Code:
Dim StrVar As String
Dim StrVar2 As String
StrVar2 = Trim$(StrVar)
Re: trim doesnt work -vba outlook
Thanks for the tip - I tried it but it Still doesn't work.
Re: trim doesnt work -vba outlook
Are you buffering the StrVar with a fixed length or anything?
Re: trim doesnt work -vba outlook
not that I know of.
my code is as simple as shown above: I need to look for two certain strings in the body of an email item (outlook) and then operate upon them ignoring any spaces chars between them.
Re: trim doesnt work -vba outlook
Just realized that your using Right. That will buffer a string of 50 chars as the way you have it setupo.
Use RTrim instead to trim blank spaces from the right side of a string.
Re: trim doesnt work -vba outlook
I'm using right to get the end of the body, and from that end I need to trim the spaces (and then Instr for the two strings).
Re: trim doesnt work -vba outlook
Try to put out that 50 character value in some of the control , i think text box would be best , just shift that value in the hided text box or some thing and then use the TRIM function , i think u can then achive ur required task.
Re: trim doesnt work -vba outlook
You can use InstrRev and Mid$ to parse a string from the right side. Otherwisae your code is not going to work because of the buffering of the string variable.
Re: trim doesnt work -vba outlook
I don't know what exactly the string will contain, so I need to Instrdev to everything besides " "
Re: trim doesnt work -vba outlook
Why not just get it all instead of getting from the end back to some point?
Re: trim doesnt work -vba outlook
because there's always a chance that similiar strings will be in the body of the text, while I'd like to act upon the strings at the end of the text.