AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Any way to easily: if last sring ends with %x%, trim %x%

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jl34567



Joined: 03 Jan 2010
Posts: 262

PostPosted: Fri Mar 05, 2010 12:38 am    Post subject: Any way to easily: if last sring ends with %x%, trim %x% Reply with quote

Subject pretty much says it all.....
Back to top
View user's profile Send private message AIM Address
entropic



Joined: 21 Dec 2008
Posts: 181

PostPosted: Fri Mar 05, 2010 12:56 am    Post subject: Reply with quote

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
View user's profile Send private message
da_boogie_man
Guest





PostPosted: Fri Mar 05, 2010 1:04 am    Post subject: Reply with quote

A simple way:

Code:

If SubStr(myVar, 0) = a
   StringTrimRight, myVar, myVar, 1


DBM
Back to top
entropic



Joined: 21 Dec 2008
Posts: 181

PostPosted: Fri Mar 05, 2010 1:55 am    Post subject: Reply with quote

Here's how to do it with regular expressions
Code:

str = This is a test
var = t

Msgbox % RegExReplace(str,  var "$")
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group