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 

Stripping out commas from a string

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



Joined: 30 Oct 2007
Posts: 13

PostPosted: Sat Mar 08, 2008 3:25 am    Post subject: Stripping out commas from a string Reply with quote

I'm having problems elminating commas from a text input string.

The input variable value is txtVar1 = 1,234. How can this string
be modified so that the variable txtVar1 will contain the value 1234
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 666
Location: MN, USA

PostPosted: Sat Mar 08, 2008 4:20 am    Post subject: Reply with quote

Code:
var=1,234
StringReplace, var, var, `,,, UseErrorLevel
MsgBox, %var% `n %ErrorLevel% commas were replaced.

_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
[VxE]



Joined: 07 Oct 2006
Posts: 1494

PostPosted: Sat Mar 08, 2008 8:06 am    Post subject: Reply with quote

Code:
String = the national debt ~= 9,400,000,000.00, and all americans have to pay it, eventually (1 , 2).
Loop, parse, String
{
   If (A_LoopField + 1)
      InANumber = yes
   If (A_LoopField = "," && InANumber = "yes")
      continue
   If !(A_LoopField + 1)
      InANumber = no
   NewString .= A_LoopField
}
msgbox %NewString%
Removes all commas that appear immediately after a nunmberal. plz forgive my coding as I am drunk ATM.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 453

PostPosted: Sat Mar 08, 2008 10:44 am    Post subject: Reply with quote

As jaco0646 demonstrated StringReplace can be used for this...

Code:
txtVar1 = 1,234
StringReplace, txtVar1, txtVar1, `,, , All

MsgBox, %txtVar1%
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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