dorit30 Posted June 23, 2008 Posted June 23, 2008 $string = "The Sum is 10.21" but i need "12.01" so how i catch only the numbers and Reverse them I got Integr and Floating Numbers plz make it function or formula
Triblade Posted June 23, 2008 Posted June 23, 2008 #Include <String.au3> ; User Defined Function $data = StringRight($string, 5) $data = _StringReverse($data) ; Ofcourse this is the more compact version: ; ; $data = _StringReverse(StringRight($string, 5)) But this is only if the last part is indeed 5 characters long. My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
dorit30 Posted June 23, 2008 Author Posted June 23, 2008 Triblade said: But this is only if the last part is indeed 5 characters long. !!!10x but i got variable text that include numbers in the mid end start Enc..so Far i go is :While $String <> "" $FixString &= StringRight($String, 1) $String = StringTrimRight($String,1) MsgBox(0, "Fixed", $FixString,1)WEndBut i stuck with the different between numbers and letters If it was just numbers its Easy (use IF) but i got Floating numbers.
martin Posted June 23, 2008 Posted June 23, 2008 dorit30 said: 10x but i got variable text that include numbers in the mid end start Enc.. so Far i go is : While $String <> "" $FixString &= StringRight($String, 1) $String = StringTrimRight($String,1) MsgBox(0, "Fixed", $FixString,1) WEnd But i stuck with the different between numbers and letters If it was just numbers its Easy (use IF) but i got Floating numbers. $string = "The Sum is 10.21"; but i need "12.01" $num = '' For $n = 1 To StringLen($string) $c = StringMid($string, $n, 1) If $c = '.' Or ($c <= '9' And $c >= '0') Then $num &= $c Next $result = '' If $num <> '' Then For $n = StringLen($num) To 1 Step -1 $result &= StringMid($num, $n, 1) Next EndIf ConsoleWrite($num & @CRLF) ConsoleWrite($result & @CRLF Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
dorit30 Posted June 23, 2008 Author Posted June 23, 2008 martin said: $string = "The Sum is 10.21"; but i need "12.01" $num = '' For $n = 1 To StringLen($string) $c = StringMid($string, $n, 1) If $c = '.' Or ($c <= '9' And $c >= '0') Then $num &= $c Next $result = '' If $num <> '' Then For $n = StringLen($num) To 1 Step -1 $result &= StringMid($num, $n, 1) Next EndIf ConsoleWrite($num & @CRLF) ConsoleWrite($result & @CRLF [u forget it ")"] Martin 10nx this is the Way 1 More Thing HOW I WRITE IT BACK IN THE STRING in the right place ??
Triblade Posted June 23, 2008 Posted June 23, 2008 $string = "The Sum is 10.21"; but i need "12.01" $num = '' For $n = 1 To StringLen($string) $c = StringMid($string, $n, 1) If $c = '.' Or ($c <= '9' And $c >= '0') Then If $num = '' Then $newstring = StringLeft($string, $n - 1) $num &= $c EndIf Next $result = '' If $num <> '' Then For $n = StringLen($num) To 1 Step -1 $result &= StringMid($num, $n, 1) Next EndIf $string = $newstring & $result I left out the Consolwrite, cause I personally don't use 'em. This: If $num = '' Then $newstring = StringLeft($string, $n - 1) and $string = $newstring & $result I added. The first line causes when the first number or . is detected the $newstring variable to contain the sentence before the detected char. The second line adds the result. My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
martin Posted June 23, 2008 Posted June 23, 2008 (edited) dorit30 said: Martin 10nx this is the Way 1 More Thing HOW I WRITE IT BACK IN THE STRING in the right place ??Not sure if I understood that. If you mean you want to replace the original number with the reversed one then $string = "The Sum is 10.21"; but i need "12.01" $num = '' $marker = 0 For $n = 1 To StringLen($string) $c = StringMid($string, $n, 1) If $c = '.' Or ($c <= '9' And $c >= '0') Then $num &= $c If $marker = 0 Then $marker = $n - 1 EndIf Next $result = '' If $num <> '' Then For $n = StringLen($num) To 1 Step -1 $result &= StringMid($num, $n, 1) Next EndIf ConsoleWrite($num & @CRLF) ConsoleWrite($result & @CRLF) $string = StringLeft($string, $marker) & $result ConsoleWrite($string & @CRLF) Edit: Triblade got there first and I like his version better. Edited June 23, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Triblade Posted June 23, 2008 Posted June 23, 2008 martin said: Not sure if I understood that. If you mean you want to replace the original number with the reversed one thenLol, 2 similar solutions that both have the same result but do it differently My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
dorit30 Posted June 23, 2008 Author Posted June 23, 2008 (edited) Triblade said: Lol, 2 similar solutions that both have the same result but do it differently Martin amd Triblade u done gr8 job its work But can i ask 1 more thing PLZ :I forget i got "%" and time like that "10:11" and Date that use "/" so i Try to fix the $c in YourS solution But no ResultI cant get it i try This : $c = '.' Or ':' Or ($c <= '9' And $c >= '0') ; for the time or this one :$c = '.' And ':' Or ($c <= '9' And $c >= '0') ; for the time can u fix it ? Edited June 23, 2008 by dorit30
Triblade Posted June 23, 2008 Posted June 23, 2008 You have to restate your variable in the Or statement. So not: $c = '.' Or ':' But $c = '.' Or $c = ':' My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
dorit30 Posted June 23, 2008 Author Posted June 23, 2008 Triblade said: You have to restate your variable in the Or statement.So not:$c = '.' Or ':'But$c = '.' Or $c = ':'Yes of course you check Again the $c if its fix Stupid me OK 10nx again
system24 Posted June 23, 2008 Posted June 23, 2008 (edited) #include<String.au3> $data = _StringReverse(String($data)) Edited June 23, 2008 by system24 [center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]
Triblade Posted June 23, 2008 Posted June 23, 2008 system24 said: #include<String.au3> $data = _StringReverse(String($data))About the same as in my Post #2 My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
dorit30 Posted June 23, 2008 Author Posted June 23, 2008 system24 said: #include<String.au3> $data = _StringReverse(String($data)) Wow u r very clever We all dont know this and u r the "Chosen 1" solve it with 1 line ....pshhh I am Happy 4 u !!! 10nx all the world is waiting 4 u 2 rise
Xandl Posted June 23, 2008 Posted June 23, 2008 Hello, this would be the regex way to extract/reverse the number: $s="The Sum is 10.21" $sr=StringRegExpReplace($s,'^([\w ]+) ([0-9.])([0-9.])?([0-9.])?([0-9.])?([0-9.])?([0-9.])?([0-9.])?([0-9.])?([0-9.])?([0-9.])?$, _ '\1 \11\10\9\8\7\6\5\4\3\2') If @error Then ConsoleWrite('err:'&@error&@LF) ConsoleWrite('res :'&$sr&@LF) This works with number parts < 11 chars (including the dot), just expand it if you need more. But I do wonder, why I was not able to successfully use this variant, to make it shorter/more versatile: $sr=StringRegExpReplace($s,'^([\w ]+) ([0-9.])([0-9.])+?$,'\1 \11\10\9\8\7\6\5\4\3\2') It seems as one needs a sufficient number of opening parenthesis for the capture, but can use a lot of backrefs, as they are empty per default. Maybe someone can shade some light on this please? ciao, Xandl
martin Posted June 23, 2008 Posted June 23, 2008 dorit30 said: Wow u r very clever We all dont know this and u r the "Chosen 1" solve it with 1 line ....pshhh I am Happy 4 u !!!10nx all the world is waiting 4 u 2 riseHow does that do what you asked for? It just reverses the whole string doesn't it? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
dorit30 Posted June 23, 2008 Author Posted June 23, 2008 martin said: How does that do what you asked for? It just reverses the whole string doesn't it?Martin 10nx 4 the time all 3 scripts do the Job include the "StringRegExpReplace" of course but its more hard then i thought the chart r i Dos so there r many sign that i have 2 filter But i got the way
weaponx Posted June 23, 2008 Posted June 23, 2008 dorit30 said: Martin 10nx 4 the time all 3 scripts do the Job include the "StringRegExpReplace" of course but its more hard then i thought the chart r i Dos so there r many sign that i have 2 filter But i got the wayPlease use proper grammar. We strive for professionalism here.
dorit30 Posted June 24, 2008 Author Posted June 24, 2008 weaponx said: Please use proper grammar. We strive for professionalism here.weaponx U can always put your Sniper in your ASS to check the grammar and c if u r Pro enough
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now