Jump to content

string help


Recommended Posts

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.

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

  • 3 months later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...