Jump to content

Splitting String to three pieces


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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