| View previous topic :: View next topic |
| Author |
Message |
jl34567
Joined: 03 Jan 2010 Posts: 262
|
Posted: Fri Mar 05, 2010 12:38 am Post subject: Any way to easily: if last sring ends with %x%, trim %x% |
|
|
| Subject pretty much says it all..... |
|
| Back to top |
|
 |
entropic
Joined: 21 Dec 2008 Posts: 181
|
Posted: Fri Mar 05, 2010 12:56 am Post subject: |
|
|
Here's a way of doing it without regular expressions
| Code: |
removeChar = x
str = The quick brown fox jumps over the lazy dog.x
str2 = The quick brown fox jumps over the lazy dog.
Msgbox % "Start String: " str "`nPossibly Trimmed String: " RemoveLast(str , removeChar)
Msgbox % "Start String: " str2 "`nPossibly Trimmed String: " RemoveLast(str2, removeChar)
Return
RemoveLast(Haystack, Needle)
{
return SubStr(Haystack, 0, 1) = Needle ? SubStr(Haystack, 1, -1) : Haystack
}
|
|
|
| Back to top |
|
 |
da_boogie_man Guest
|
Posted: Fri Mar 05, 2010 1:04 am Post subject: |
|
|
A simple way:
| Code: |
If SubStr(myVar, 0) = a
StringTrimRight, myVar, myVar, 1
|
DBM |
|
| Back to top |
|
 |
entropic
Joined: 21 Dec 2008 Posts: 181
|
Posted: Fri Mar 05, 2010 1:55 am Post subject: |
|
|
Here's how to do it with regular expressions
| Code: |
str = This is a test
var = t
Msgbox % RegExReplace(str, var "$")
|
|
|
| Back to top |
|
 |
|