Jump to content
Sign in to follow this  
geezery

Splitting String to three pieces

Recommended Posts

geezery

I need help splitting my string it to three pieces and to put those in the list element.

I managed to split it on two pieces, but I didn't figure how I can split string to three pieces.

String:

10.6.2007 0:00;192.168.1.1;text in here

Delimiter is ; like in csv.

Share this post


Link to post
Share on other sites
poisonkiller

$var = StringSplit("10.6.2007 0:00;192.168.1.1;text in here", ";")oÝ÷ ÛMú½ªôríj)ì&j|©ç±ªÞ¶«{Mú½ªõ

Edited by poisonkiller

Share this post


Link to post
Share on other sites
geezery

Thanks for the tip, but I still can't populate my list. I think that there is something wrong with the For loop.

Func _UpdateList()
                _GUICtrlListClear($TimeList)
    _GUICtrlListClear($IpList)
    _GUICtrlListClear($InfoList)
    Dim $ReadedFile
    _FileReadToArray("IPS.txt",$ReadedFile)
For $i = $ReadedFile[1] to 0 step -1
    $Splitted = StringSplit($ReadedFile[$i],";")
                _GUICtrlListAddItem($Timelist,$Splitted[0])
    _GUICtrlListAddItem($IpList,$Splitted[1])
    _GUICtrlListAddItem($InfoList,$Splitted[2])
    
Next
EndFunc
Edited by geezery

Share this post


Link to post
Share on other sites
SpookMeister

Thanks for the tip, but I still can't populate my list. I think that there is something wrong with the For loop.

Func _UpdateList()
                _GUICtrlListClear($TimeList)
    _GUICtrlListClear($IpList)
    _GUICtrlListClear($InfoList)
    Dim $ReadedFile
    _FileReadToArray("IPS.txt",$ReadedFile)
For $i = $ReadedFile[1] to 0 step -1
    $Splitted = StringSplit($ReadedFile[$i],";")
                _GUICtrlListAddItem($Timelist,$Splitted[0])
    _GUICtrlListAddItem($IpList,$Splitted[1])
    _GUICtrlListAddItem($InfoList,$Splitted[2])
    
Next
EndFunc
As a guess, shouldnt that be For $i = $ReadedFile[0] to 0 step -1

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
poisonkiller

As a guess, shouldnt that be For $i = $ReadedFile[0] to 0 step -1

I was thinking more like this:

For $i = $ReadedFile[0] to 1 step -1

Share this post


Link to post
Share on other sites
geezery

I had it just like poisonkiller putted. But when I compile the script and execute it only flashes and closes.

#include <GUIConstants.au3>
#include <GuiList.au3>
#include <GuiListView.au3>
#include <file.au3>
; Change to OnEvent mode
Opt("GUIOnEventMode", 1) 

;Main Gui and it Controls
$MainWindow = GUICreate("date", 1024, 768,50, 10, 0x04CF0000) 
$LabelIP = GUICtrlCreateLabel("IP-Address",205,20)
$LabelInfo = GUICtrlCreateLabel("text",310,20)
$TimeList=GUICtrlCreateList ("" , 100,34,100,700)
$IpList=GUICtrlCreateList ("" , 200,34,100,700)
$InfoList=GUICtrlCreateList ("" , 300,34,700,700)
GUISetState(@SW_SHOW)

;Activate the Window Close Button
GUISetOnEvent($GUI_EVENT_CLOSE, "_Terminate")

;Main Program


;Call Functions.
While 1
;Declare how often functions are reloaded
_UpdateList()
$RefreshDelay = 10000
sleep ($RefreshDelay)
wend

;Functions

Func _UpdateList()
    Dim $IpList, $InfoList, $TimeList
    _GUICtrlListClear($TimeList)
    _GUICtrlListClear($IpList)
    _GUICtrlListClear($InfoList)
    Dim $ReadedFile
    _FileReadToArray("IPS.txt",$ReadedFile)
For $i = $ReadedFile[0] to 1 step -1
    $Splitted = StringSplit($ReadedFile[$i],";")
    _GUICtrlListAddItem($TimeList,$Splitted[0])
    _GUICtrlListAddItem($IpList,$Splitted[0])
    _GUICtrlListAddItem($InfoList,$Splitted[1])
Next
EndFunc

;Close Button
Func _Terminate()
$started = 0
Exit
EndFunc
Edited by geezery

Share this post


Link to post
Share on other sites
geezery

What am I missing here?

Share this post


Link to post
Share on other sites
poisonkiller

Try changing this line in _UpdateList() function:

Dim $ReadedFile

to this:

Dim $ReadedFile[_FileCountLines("IPS.txt")+1]

Share this post


Link to post
Share on other sites
geezery

Thanks it works, but I cant find any data on _GUICtrlListAddItem($InfoList,$Splitted[3])

Only [1] = 10.6.2007 0:00

[2] = 192.168.1.1

Where is the text cell?

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  

×