Jump to content
Sign in to follow this  
Cap0

string help

Recommended Posts

Cap0

Hi, How would i change this string:

$str = "1005194"

to:

$str = "94510001"

i've tried cutting each 2 numbers and stringreplacing then stringinserting, but it's just too confusing.

Share this post


Link to post
Share on other sites
BrettF

Hi, How would i change this string:

$str = "1005194"

to:

$str = "94510001"

i've tried cutting each 2 numbers and stringreplacing then stringinserting, but it's just too confusing.

So you want to take the bigest number in the string, shove at the start, then put it in reverse order? How are you trying to manipulate it?

Share this post


Link to post
Share on other sites
SoeMinnMinn

Please try this function

Func StringNumReverse($strVal, $num = 2)
;$strIn = "1005194"
;$strOut = "94510001"
    Local $strBase = $strVal
    Local $strTemp = ""
    Local $iCount = 0
    Local $iRep = 0
    Local $l = 0
    
    If StringLen($strVal) < $num Then Return ""
    
    If StringLen($strVal) <> ((Int(StringLen($strVal)/ $num)) * $num) Then
        $iRep = $num - (StringLen($strVal) - ((Int(StringLen($strVal)/ $num)) * $num))
    Else
        $iRep = 0
    EndIf
    
    For $l = 1 To $iRep
        $strBase = "0" & $strBase
    Next
    
    $iCount = StringLen($strBase)/ $num
    For $l = 1 To $iCount
        $strTemp = $strTemp & StringMid($strBase, (StringLen($strBase) - ($l * $num) + 1), $num)
    Next
    
    Return $strTemp
EndFunc

$strIn = "1005194"
$strOut = StringNumReverse($strIn, 2);"94510001";194005001
MsgBox(0, "", $strOut)
Exit

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  

×