Sign in to follow this  
Followers 0
bgjensen

StringSplit Problem

3 posts in this topic

I have a problem with the StringSplit function:

I have this code:

$file = FileOpen("test1.txt", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    $array = StringSplit($line, ";")
    GUICtrlCreateListViewItem($array[1] & "|" & $array[2] & "|" & $array[3] & "|" & $array[4] & "|" & $array[5], $listview)
    If @error = -1 Then ExitLoop
Wend

FileClose($file)

And in my test1.txt is something like this:

value1;value2;value3;value4;value5

But if one of the value is empty like this:

value1;value2;;value4;value5

The script fails, because $array[3] will be empty, is there a solution to this???

Share this post


Link to post
Share on other sites



I've tested so and it works fine:

$str = 'value1;value2;;value4;value5'
$aSplit = StringSplit($str, ';')
$sItem = ''
For $i = 1 To UBound($aSplit) -1
    $sItem &= $aSplit[$i] & '|'
Next
$sItem = StringTrimRight($sItem, 1)

GUICreate('')
$lv = GUICtrlCreateListView('  1  |  2  |  3  |  4  |  5  ', 10, 10, 250)
GUICtrlCreateListViewItem($sItem, $lv)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Best Regards BugFix  

Share this post


Link to post
Share on other sites

Thanks works perfectly.

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