Jump to content

Recommended Posts

Posted (edited)
  On 10/24/2013 at 8:57 PM, guinness said:

kylomas,

You don't need to escape | in a character class.

 

Thanks, good to know...non the less it works...

edit: although I think I like UEZ's solution better...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

It's unforgiving, though it shouldn't be. Help file denotes which should be escaped and which special characters retaining their meaning. R doesn't which I found out the other day!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 10/24/2013 at 8:55 PM, jdelaney said:

 

here ya go...if you want an array for each line

#include <array.au3>
$string = "Info1||||Info2||||Info3||||Info4" & @CRLF & _
"Info5||||Info6||||Info7||||Info8" & @CRLF & _
"Info9||||Info10||||Info11||||Info12"
ConsoleWrite($string)

$aCRLFSplit = StringSplit($string,@CRLF,3)
For $i = 0 To UBound($aCRLFSplit)-1
    $aCRLFSplit[$i] = StringSplit($aCRLFSplit[$i],"||||",3)
    _ArrayDisplay($aCRLFSplit[$i])
Next

Nearly ;) I got it working when replacing @CRLF with @LF :P

Otherwise if you use @CRLF this will happen:

4csa6pce.png

Posted (edited)

interesting, I can't reproduce that...i get an array of three arrays, each with 4 values

edited to output the arrays:

#include <array.au3>

$string = "Info1||||Info2||||Info3||||Info4" & @CRLF & _
"Info5||||Info6||||Info7||||Info8" & @CRLF & _
"Info9||||Info10||||Info11||||Info12"
;~ ConsoleWrite($string & @CRLF)

$aCRLFSplit = StringSplit($string,@CRLF,3)
For $i = 0 To UBound($aCRLFSplit)-1
    $aCRLFSplit[$i] = StringSplit($aCRLFSplit[$i],"||||",3)
    ConsoleWrite(_ArrayToString($aCRLFSplit[$i]) & @CRLF)
Next

where output is:

Info1|Info2|Info3|Info4
Info5|Info6|Info7|Info8
Info9|Info10|Info11|Info12

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

Is it possible to add the splitted items in a listview, so i can view it more clear?

Like Info1 is the Itemtext and for subitem 1 i get the first split which is info2 etc etc.

And by @LF (Linefeed) I create a new ListViewItem, and also split into the subitems by ||| ?

Because the console writeline is not that clear.

Also I like to visualize my splitted stuff in a gui app (No Array_Display)

Posted (edited)

not sure, exactly what you need...added 2 loops to create a 2d array, and to ouput through the array of arrays

#include <array.au3>

$string = "Info1||||Info2||||Info3||||Info4" & @CRLF & _
"Info5||||Info6||||Info7||||Info8" & @CRLF & _
"Info9||||Info10||||Info11||||Info12"
;~ ConsoleWrite($string & @CRLF)

$aCRLFSplit = StringSplit($string,@CRLF,3)
For $i = 0 To UBound($aCRLFSplit)-1
    $aCRLFSplit[$i] = StringSplit($aCRLFSplit[$i],"||||",3)
;~  ConsoleWrite(_ArrayToString($aCRLFSplit[$i]) & @CRLF)
Next

For $i = 0 To UBound($aCRLFSplit)-1
    $aTemp = $aCRLFSplit[$i]
    For $j = 0 To UBound($aTemp)-1
        ConsoleWrite("Array[" & $i & "]; SubArray[" & $j & "] value=[" & $aTemp[$j] & "]." & @CRLF)
    Next
Next

; sample of creating a 2d array
Local $2DArray[UBound($aCRLFSplit)][1]
For $i = 0 To UBound($aCRLFSplit)-1
    $aTemp = $aCRLFSplit[$i]
    If UBound($aTemp) > UBound($2DArray,2) Then
        ReDim $2DArray[UBound($aCRLFSplit)][UBound($aTemp)]
    EndIf
    For $j = 0 To UBound($aTemp)-1
        $2DArray[$i][$j] = $aTemp[$j]
    Next
Next
_ArrayDisplay($2DArray)
; sample of creating a transposed 2d array
Local $2DArrayTransposed[1][UBound($aCRLFSplit)]
For $i = 0 To UBound($aCRLFSplit)-1
 $aTemp = $aCRLFSplit[$i]
 If UBound($aTemp) > UBound($2DArrayTransposed) Then
  ReDim $2DArrayTransposed[UBound($aTemp)][UBound($aCRLFSplit)]
 EndIf
 For $j = 0 To UBound($aTemp)-1
  $2DArrayTransposed[$j][$i] = $aTemp[$j]
 Next
Next
_ArrayDisplay($2DArrayTransposed)











added another case for a transposed 2d array

gui demonstration:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

$string = "Info1||||Info2||||Info3||||Info4" & @CRLF & _
"Info5||||Info6||||Info7||||Info8" & @CRLF & _
"Info9||||Info10||||Info11||||Info12"
;~ ConsoleWrite($string & @CRLF)

$iGuiWidth = 200
$iControlHeight = 20
$iControlBuffer = 10
$iControlWidth  = $iGuiWidth-$iControlBuffer*2

$aCRLFSplit = StringSplit($string,@CRLF,3)
$iGuiHeight = ((UBound($aCRLFSplit)+1)*$iControlBuffer) + (UBound($aCRLFSplit)*$iControlHeight)
$hGui = GUICreate("something",$iGuiWidth,$iGuiHeight)

For $i = 0 To UBound($aCRLFSplit)-1
    $aCRLFSplit[$i] = StringSplit($aCRLFSplit[$i],"||||",3)
    GUICtrlCreateCombo("Line" & $i+1 & "'s split",$iControlBuffer,$iControlBuffer+($i*$iControlBuffer+$i*$iControlHeight),$iControlWidth,$iControlHeight)
    GUICtrlSetData(-1,_ArrayToString($aCRLFSplit[$i]))
Next

GUISetState(@SW_SHOW)
Do
    Local $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Exit
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

Boom...shot that moving target...

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***

#include <array.au3>
#AutoIt3Wrapper_Add_Constants=n

local $str

$str &= 'Info1||||Info2||||Info3||||Info4' & @lf
$str &= 'Info5||||Info6||||Info7||||Info8' & @lf
$str &= 'Info9||||Info10||||Info11||||Info12'

local $array = stringsplit($str,@lf,2)

local $gui = guicreate('Huh ??!???')

local $lv = guictrlcreatelistview('Item1|Item2|Item3|Item4',10,10,300,300)

for $1 = 0 to ubound($array) - 1
    ConsoleWrite($array[$1] & @LF)
    GUICtrlCreateListViewItem(stringreplace($array[$1],'||||','|'),$lv)
next

guisetstate()

while 1
    switch guigetmsg()
        Case $GUI_EVENT_CLOSE
            Exit
    endswitch
wend

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Posted

copied, and made dynamic :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

$string = "Info1||||Info2||||Info3||||Info4" & @CRLF & _
"Info5||||Info6||||Info7||||Info8" & @CRLF & _
"Info9||||Info10||||Info11||||Info12"
;~ ConsoleWrite($string & @CRLF)
$aCRLFSplit = StringSplit($string,@CRLF,3)
For $i = 0 To UBound($aCRLFSplit)-1
    $aCRLFSplit[$i] = StringSplit($aCRLFSplit[$i],"||||",3)
Next

$iSubItems = 0
For $i = 0 To UBound($aCRLFSplit)-1
    $aTemp = $aCRLFSplit[$i]
    If UBound($aTemp) > $iSubItems Then $iSubItems = UBound($aTemp)
Next

For $i = 1 To $iSubItems
    If $i = 1 Then
        $sHeader = "Item" & $i
    Else
        $sHeader &= "|Item" & $i
    EndIf
Next

$iGuiWidth = 75*$iSubItems
$iControlHeight = 20
$iControlBuffer = 10
$iControlWidth  = $iGuiWidth-$iControlBuffer*2
$iGuiHeight = (2*$iControlBuffer) + (UBound($aCRLFSplit)*$iControlHeight)+20
$hGui = GUICreate("something",$iGuiWidth,$iGuiHeight)
local $lv = guictrlcreatelistview($sHeader,$iControlBuffer,$iControlBuffer,$iGuiWidth-$iControlBuffer*2,$iGuiHeight-$iControlBuffer*2)
for $i = 0 to ubound($aCRLFSplit) - 1
    GUICtrlCreateListViewItem(_ArrayToString($aCRLFSplit[$i]),$lv)
next

GUISetState(@SW_SHOW)
Do
    Local $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

This is great!  This is what I need as well but less advanced.  I just wanted to split the string by a list of input delimited by the "return" key.

Are we having coding battle?  If so, I'd like to know so I can pick side.  :D

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
  • Recently Browsing   0 members

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