Sign in to follow this  
Followers 0
bogQ

How to split string on alfa and numeric and put it to array

8 posts in this topic

"710037HK32978BKKK310203EGNL904350FS18000AB"

basicly i need 18000 so that i can add +1 on every loop so that i can send it when i rebuild the string from array (+1 on last numeric chars)

SN:/ "710037HK32978BKKK310203EGNL904350FS18000AB"

SN:/ "710037HK32978BKKK310203EGNL904350FS18001AB"

SN:/ "710037HK32978BKKK310203EGNL904350FS18002AB"

[0] 10

[1] 710037

[2] HK

[3] 32978

[4] BKKK

[5] 310203

[6] EGNL

[7] 904350

[8] FS

[9] 18000

[10] AB

at the moment im trying it to check every position with stringmid combinated with srtinglen and try to determen on what position i need to split the string so that i can rebuild it later.

Is there some other faster solution to do this (to split string on alpha and num chars)?


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites



"710037HK32978BKKK310203EGNL904350FS18000AB"

basicly i need 18000 so that i can add +1 on every loop so that i can send it when i rebuild the string from array (+1 on last numeric chars)

SN:/ "710037HK32978BKKK310203EGNL904350FS18000AB"

SN:/ "710037HK32978BKKK310203EGNL904350FS18001AB"

SN:/ "710037HK32978BKKK310203EGNL904350FS18002AB"

[0] 10

[1] 710037

[2] HK

[3] 32978

[4] BKKK

[5] 310203

[6] EGNL

[7] 904350

[8] FS

[9] 18000

[10] AB

at the moment im trying it to check every position with stringmid combinated with srtinglen and try to determen on what position i need to split the string so that i can rebuild it later.

Is there some other faster solution to do this (to split string on alpha and num chars)?

StringRegExp(), but you'll have to be specific about the expected format and what you want to get your pattern. What do you know about the string? Is the number always just before two alpha chars at the end of the string? Is the number variable length? Do you need all the other parts as separate elements, or just "before", "number", "after"?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

StringRegExp(), but you'll have to be specific about the expected format and what you want to get your pattern. What do you know about the string? Is the number always just before two alpha chars at the end of the string? Is the number variable length? Do you need all the other parts as separate elements, or just "before", "number", "after"?

:)

Is the number always just before two alpha chars at the end of the string? no, the serial number can b all in numeric or in the worst case numeric mixed with letters. In some cases it can b "ELD859501BT3615669" in some casses "8600115141210"

Is the number variable length? its difrent from one serial on the product to another

Do you need all the other parts as separate elements, or just "before", "number", "after"? basicly i need only last numeric part to go in +1, i tought that its easyer to split it to numeric and alpha and rebuild it, if there is a way to do...

[0] 3

[1] 710037HK32978BKKK310203EGNL904350FS

[2] 18000 ;<== +1

[3] AB"

... pls point me to that direction.

edit:

is there way to find last numeric chars in string so that i can replace them with +1 with stringreplace?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

"710037HK32978BKKK310203EGNL904350FS18000AB"

basicly i need 18000 so that i can add +1 on every loop so that i can send it when i rebuild the string from array (+1 on last numeric chars)

SN:/ "710037HK32978BKKK310203EGNL904350FS18000AB"

SN:/ "710037HK32978BKKK310203EGNL904350FS18001AB"

SN:/ "710037HK32978BKKK310203EGNL904350FS18002AB"

[0] 10

[1] 710037

[2] HK

[3] 32978

[4] BKKK

[5] 310203

[6] EGNL

[7] 904350

[8] FS

[9] 18000

[10] AB

at the moment im trying it to check every position with stringmid combinated with srtinglen and try to determen on what position i need to split the string so that i can rebuild it later.

Is there some other faster solution to do this (to split string on alpha and num chars)?

Try this.

#Include <Array.au3>

const $SN = '710037HK32978BKKK310203EGNL904350FS18000AB'

dim $Array = _StringSplit2BogQ($SN)

_ArrayDisplay($Array)

func _StringSplit2BogQ($sString)
    
    dim $Array[1] = [0]
    
    local $c, $b, $n, $r = false

    while $sString > ''
        $c = Stringleft($sString, 1)
        $sString = StringTrimLeft($sString, 1)
        $n = ($c >= '0') and ($c <= '9')
        if $Array[0] = 0 then
            $b = $n
            $r = 1
        else
            if $b then
                if not $n then
                    $b = not $b
                    $r = 1
                endif
            else
                if $n then
                    $b = not $b
                    $r = 1
                endif
            endif
        endif
        if $r then
            redim $Array[$Array[0] + 2]
            $Array[0] += 1
            $Array[$Array[0]] = $c
            $r = 0
        else
            $Array[$Array[0]] &= $c
        endif
    wend
    return $Array
endfunc; _StringSplit2BogQ
Edited by Yashied

Share this post


Link to post
Share on other sites

#include <Array.au3>

Dim $sStr = '710037HK32978BKKK310203EGNL904350FS18000AB'
Dim $aMatch = StringRegExp($sStr, '([A-Z]+|[0-9]+)', 3)

If IsArray($aMatch) Then
    _ArrayInsert($aMatch, 0, UBound($aMatch))
    _ArrayDisplay($aMatch)
    
    For $i = 1 To 10
        $aMatch[$aMatch[0]-1] += 1
        ConsoleWrite(_ArrayToString($aMatch, '') & @LF)
    Next
EndIf

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <Array.au3>

Dim $sStr = '710037HK32978BKKK310203EGNL904350FS18000AB'
Dim $aMatch = StringRegExp($sStr, '([A-Z]+|[0-9]+)', 3)

If IsArray($aMatch) Then
    _ArrayInsert($aMatch, 0, UBound($aMatch))
    _ArrayDisplay($aMatch)
    
    For $i = 1 To 10
        $aMatch[$aMatch[0]-1] += 1
        ConsoleWrite(_ArrayToString($aMatch, '') & @LF)
    Next
EndIf
I think, ... I need better study StringRegExp() function.

:)

Edited by Yashied

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

...and the inverted greediness quantifier shall lead them:

#include <Array.au3>

Global $avInputs[5] = ["3710037HK32978BKKK310203EGNL904350FS18000AB", _
"ELD859501BT3615669", "8600115141210", "ABCDefghIJKLmnop", "710037HK32978BKKK310203EG.NL904350FS18#0_0-100AB"]
Global $avOutputs[UBound($avInputs)], $avRegExp

_ArrayDisplay($avInputs, "$avInputs")

For $n = 0 To UBound($avInputs) - 1
    $avRegExp = StringRegExp($avInputs[$n], "(?U)(.*)(\d+)(\D*)\z", 3)
    If @error Then
        $avOutputs[$n] = "Error (no digits):  " & $avInputs[$n]
    Else
        $avRegExp[1] += 1
        For $i = 0 to UBound($avRegExp) - 1
            If StringStripWS($avInputs[$i], 8) <> "" Then $avOutputs[$n] &= $avRegExp[$i]
        Next
    EndIf
Next

_ArrayDisplay($avOutputs, "$avOuputs")

Note handling is required for possibility that there are no digits in the string.

:)

Edit: Updated to include input example with non-alphanum chars.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

ty all :)

#include <Array.au3>
Global $serial,$h
$CountOfSerials = 10
Dim $sStr = '710037HK32978BKKK310203EG.NL904350FS18#0_0-100AB'
Dim $aMatch = StringRegExp($sStr, '([A-Z]+|[#]+|[-]+|[_]+|[.]+|[0-9]+)', 3)

If IsArray($aMatch) Then
    MsgBox(0,"",$sStr)
;~  Send($serial,1)
;~  Send("{ENTER}")
    _ArrayInsert($aMatch, 0, UBound($aMatch))
;~  _ArrayDisplay($aMatch)
    Do
        For $f = $aMatch[0] To 1 Step -1
            If Not StringIsAlpha($aMatch[$f]) Then
                $data = $aMatch[$f]
                _ArrayDelete($aMatch,$f)
                _ArrayInsert($aMatch,$f,$data+1 )
                ExitLoop(1)
            EndIf
        Next
        For $y = 1 To $aMatch[0]
            $serial = $serial&$aMatch[$y]
        Next
        MsgBox(0,"",$serial)
;~      Send($serial,1)
;~      Send("{ENTER}")
        $serial = ""
        $h += 1
    Until $h = $CountOfSerials-1
EndIf

I think, ... I need better study StringRegExp() function.

:party:

me too :idea:

edit:

Note handling is required for possibility that there are no digits in the string.

:P

serial number with no digits in it isnt serial :P ty all once more

edit: editing so that i have thisone documented

another way

$serial = "abc123(*&^990j0a987079898da989o987%*&&)(%&$877654kh;l"
$len = StringLen($serial)
Global $number,$on,$first,$second
For $x = $len To 1 Step -1
    $l = StringMid($serial, $x, 1)
    If $l = "1" Or $l = "2" Or $l = "3" Or $l = "4" Or $l = "5" Or $l = "6" Or $l = "7" Or $l = "8" Or $l = "9" Or $l = "0" Then
        $number = $l&$number
        $on = "im on"
    Else
        If $on = "im on" Then
            $pos = $x
            ExitLoop(1)
        EndIf
    EndIf
Next
If $number = "" Then
    $number = $serial
Else
    $first = StringLeft($serial,$pos)
    $second = StringMid($serial,$pos+StringLen($number)+1,$len-($pos+StringLen($number)))
EndIf
MsgBox(0,$number,$first&$number&$second)
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

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