huldu Posted February 17, 2009 Share Posted February 17, 2009 Hi! I was just wondering if someone knew a script that looks through a .csv file and creates columns and values from the .csv. Ive used the search function, of course, but it wouldnt let me search for a short word as "csv". Also tried search for string but that ended up with a gazillion results Basically its a really simple script(i hope lol), that looks through a .csv like this: DescID,TextDescription,Health,Loyalty,Endurance,Smarts,Attention,FOVRange,FOVAngle,EvidenceRating,Va lueRating,ThreatRating,HeatGenerated,Armour.Health,Armour.Loyalty,Armour.Smarts,Armour.Attention,Arm our.Endurance 1,A_MEGALOMANIAC_CRIMINAL_MASTERMIND,100,100,100,100,100,30,0.7,25,6,35,10,80,80,80,80,80 2,A_LADY_MEGALOMANIAC_CRIMINAL_MASTERMIND,100,100,100,100,100,30,0.7,25,6,35,10,80,80,80,80,80 3,DRAGON_VAN_DEN_DRIESSCHE,100,100,100,100,100,30,0.7,25,6,35,10,80,80,80,80,80 The problem is i have no clue whatsoever how to get anything to work. However i did find this code here which seems to work pretty well: #include <array.au3> $sString = 'DescID,TextDescription,Health,Loyalty,Endurance,Smarts,Attention,FOVRange,FOVAngle,EvidenceRatin g,ValueRating,ThreatRating,HeatGenerated,Armour.Health,Armour.Loyalty,Armour.Smarts,Armour.Attention ,Armour.Endurance' $a = _SplitStr($sString, ',') _ArrayDisplay($a, '') Func _SplitStr($sString, $vDelim) Local $aDQ = StringRegExp($sString, '".*?"', 3) If IsArray($aDQ) = 0 Then Return StringSplit($sString, $vDelim) For $iCC = 0 To UBound($aDQ) - 1 $sString = StringReplace($sString, $aDQ[$iCC], 'SplitStr' & $iCC & 'Hold', 1, 1) Next Local $aSplit = StringSplit($sString, $vDelim) For $iCC = 1 To UBound($aSplit) - 1 For $xCC = 0 To UBound($aDQ) - 1 $aSplit[$iCC] = StringReplace($aSplit[$iCC], 'SplitStr' & $xCC & 'Hold', $aDQ[$xCC]) Next Next Return $aSplit EndFunc But of course i wouldnt know how to script it to look for the first line in the .csv to create the columns, then look below for the "values"... complicated I was hoping someone knew a script that did all this on this forum and could link it to me, please "I'm paper, rock is fine, nerf scissors!!!" Link to comment Share on other sites More sharing options...
Authenticity Posted February 17, 2009 Share Posted February 17, 2009 The first regex will always return non array and thus return StringSpilt... Can you give an example of the desired results? Link to comment Share on other sites More sharing options...
huldu Posted February 17, 2009 Author Share Posted February 17, 2009 (edited) The first regex will always return non array and thus return StringSpilt... Can you give an example of the desired results? Basically the goal would be to load the .csv file, the script would go through the file and create columns and add the values to them. The values would be saved in an array. It would look something like this: [DescID], [TextDescription], [Health], [Loyalty].... 1 A_MEGALOM.. 100 100 2 A_LADY_ME... 100 100 3 DRAGON_... 100 100 And so on. The goal would be to get the columns up and adding the values for each of the columns through all the classes. The end result would be to have everything in a GUI, but that is something i can do. I would get all the column names so i can add them to the GUI, then have all the values added to each column. Edited February 17, 2009 by huldu "I'm paper, rock is fine, nerf scissors!!!" Link to comment Share on other sites More sharing options...
Authenticity Posted February 18, 2009 Share Posted February 18, 2009 #include <array.au3> Dim $sCSV = 'DescID,TextDescription,Health,Loyalty,Endurance,Smarts,Attention,FOVRange,FOVAngle,EvidenceRating,ValueRating,' & _ 'ThreatRating,HeatGenerated,Armour.Health,Armour.Loyalty,Armour.Smarts,Armour.Attention,Armour.Endurance' & _ '1,A_MEGALOMANIAC_CRIMINAL_MASTERMIND,100,100,100,100,100,30,0.7,25,6,35,10,80,80,80,80,80' & @LF & _ '2,A_LADY_MEGALOMANIAC_CRIMINAL_MASTERMIND,100,100,100,100,100,30,0.7,25,6,35,10,80,80,80,80,80' & @LF & _ '3,DRAGON_VAN_DEN_DRIESSCHE,100,100,100,100,100,30,0.7,25,6,35,10,80,80,80,80,80' Dim $aTmp = StringRegExp($sCSV, '\G(?i)([a-z]+\.?[a-z]*),?', 3) Dim $aAtt[1] Dim $aItems If IsArray($aTmp) Then ReDim $aAtt[1][UBound($aTmp)+1] For $i = 0 To UBound($aTmp)-1 $aAtt[0][$i] = $aTmp[$i] Next $aItems = StringRegExp($sCSV, '(?>\d.*)', 3) If IsArray($aItems) Then For $i = 0 To UBound($aItems)-1 Local $ih = UBound($aAtt, 1) ReDim $aAtt[$ih+1][UBound($aAtt, 2)] Local $aItem = StringSplit($aItems[$i], ',', 2) For $j = 0 To UBound($aItem)-1 $aAtt[$ih][$j] = $aItem[$j] Next Next EndIf EndIf If IsArray($aAtt) Then _ArrayDisplay($aAtt) Does the .csv file contain any line feed separators? Link to comment Share on other sites More sharing options...
Bert Posted February 18, 2009 Share Posted February 18, 2009 Look at Excel.au3. That can do what you need. It is part of the AutoIt suite, and is in the help file. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now