Jump to content

Is there a quickie multi-dim SplitString()


Recommended Posts

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'

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

 

Link to comment
Share on other sites

:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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