Sign in to follow this  
Followers 0
dorit30

_StringReverse problem

19 posts in this topic

$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

Share this post


Link to post
Share on other sites



#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)

Share this post


Link to post
Share on other sites

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)

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

$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 ??

Share this post


Link to post
Share on other sites

$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)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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 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.

Share this post


Link to post
Share on other sites

Not sure if I understood that. If you mean you want to replace the original number with the reversed one then

Lol, 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)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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 Result

I 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 by dorit30

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

#include<String.au3>

$data = _StringReverse(String($data))

Edited by system24

[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

How 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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Please use proper grammar. We strive for professionalism here.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0