Sign in to follow this  
Followers 0
sshrum

Is there a quickie multi-dim SplitString()

8 posts in this topic

Given:

"test|foo|bar;test2|bar|foo;Test3|boo|far"

...is there a quick way to split the sting into a multi-dim array?

Split 1 on ";" Split 2 on "|" yielding:

[test][foo][bar]

[test2][bar][foo]

[test2][boo][far]

If not, is there a easy way to do this...I'm getting ready to just write a function but I usually tend to over think these things and 9 outta 10 times someone points me in the right direction.

TIA


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites



Search the forum for "stringsplit array" and select "Only search in titles" and you will find a lot of hits.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yes, because stringsplit deals with SINGLE dimensioned arrays so, over course there will be a TON of hits...but basically it's finding a needle in the outback for 1 or 2 dealing with MULTI dimensioned arrays.

Following your suggestion however, I haven't found anything that looks like what I was after...I do see a ton of ppl doing what I was going to do which was to code the multi dim array with a loop of my own but that doesn't answer the question:

Does a function exist to take a string with 2 delimiters to create a multi-dim array?

You might as well have sed to look at every forum post and eventually I'll find it. Sometimes the direct approach is faster and easier...you sir, are the contradiction to that statement.

Sry, it's late and I know you're just trying to empower me... :-S


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

Yes, because stringsplit deals with SINGLE dimensioned arrays so, over course there will be a TON of hits...but basically it's finding a needle in the outback for 1 or 2 dealing with MULTI dimensioned arrays.

On the first page you'll find what you need. I tried the search myself but was too lazy to copy the links.

Does a function exist to take a string with 2 delimiters to create a multi-dim array?

No.

You might as well have sed to look at every forum post and eventually I'll find it. Sometimes the direct approach is faster and easier...you sir, are the contradiction to that statement.

This is the old "Give a man a fish or teach him how to fish" discussion.

Here is a fish:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I saw that fish (er, post). I figured someone woulda put a multi delimiter function together like StringSplit2d($String, ";", "|"). The one here uses @LF as the first delimiter. Guess I'll just write one for myself.

Thx.


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites
:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Taken from my CSVSplit function. Slight modification to code. I think you should try and turn this into a proper function along with error checks. Your idea BTW. :)

#include <Array.au3>

Dim $sString = "test|foo|bar;test2|bar|foo;Test3|boo|far"
Dim $asDelim[2] = [";","|"]

$iOverride = 0
$aArray = StringSplit($sString, $asDelim[0], 2) ; Split to get rows
$iBound = UBound($aArray)

Dim $aReturn[$iBound][2], $aTemp
For $i = 0 To $iBound -1
    $aTemp = StringSplit($aArray[$i], $asDelim[1]) ; Split to get row items
    If Not @error Then
        If $aTemp[0] > $iOverride Then
            $iOverride = $aTemp[0]
            ReDim $aReturn[$iBound][$iOverride] ; Add columns to accomodate more items
        EndIf
    EndIf
    For $j = 1 To $aTemp[0]
        If StringLen($aTemp[$j]) Then
            $aReturn[$i][$j -1] = $aTemp[$j] ; Populate each row
        EndIf
    Next
Next

_ArrayDisplay($aReturn)
Edited by czardas

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