Reaper HGN Posted February 12, 2009 Posted February 12, 2009 Try my "_tokenizer": http://www.autoitscript.com/forum/index.ph...st&p=248768. Remember to define the delimiter variables!CheersKurtKurt,I want to add my "Thank You" as I was struggling a bit with a csv file that contained commas within quotes within fields. Your code worked cut n paste without any modifications. Excellent!
Manjish Posted February 12, 2009 Posted February 12, 2009 ppl, just used this.. n it will work irrespective of anything.. v simple, too.. just the regular old stringsplit.. please see, eventhough i know that this topic has gone off to a different point from where it started.. #include<array.au3> $string='jhsdbcjhgbs,jhjhadfvjbajv,"jjsabdjb","AJHKJHA",HDHD' $array=StringSplit($string,",") _ArrayDisplay($array,"") [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
wolf9228 Posted February 12, 2009 Posted February 12, 2009 (edited) My string looks like somthing like this. example: $String = xyz,"$1,823",38.34,34 South East Blvd.,Jax, NC, 42789 I am using: $array = StringSplit($String,",") $value2 = $array[2] I should be getting $value2 = "$1,823", but I am getting "$1 . Is there a way to split the string without it splitting it at the comma inside quotes? Thanks. delimiters quotes "String" quotes delimiters expandcollapse popup#Include <Array.au3> $String = 'xyz,"$1,823","38.34,34 South East Blvd.",Jax, NC, 42789' $delimiters = "," $quotes = '"' $SplitArray = String_Split($String,$delimiters,$quotes) _ArrayDisplay($SplitArray, "") $String = 'xyz,"$1,823,38.34",34 South East Blvd.,Jax, NC, 42789' $delimiters = "," $quotes = '"' $SplitArray = String_Split($String,$delimiters,$quotes) _ArrayDisplay($SplitArray, "") Func String_Split($string = "" ,$delimiters = ",",$quotes = '"') Local $SplitArray[1] , $TXT = "" ,$TXT2 = "" , $I = 0 ,$Y ,$X $SplitArray[0] = 0 Do $I += 1 $StringMid = StringMid ($string, $I, 1) $TXT &= $StringMid IF $StringMid = $delimiters Then Select Case StringInStr ( $TXT ,$quotes) = True $X = $I $Y = False Do $X +=1 $StringMid2 = StringMid ($String, $X, 1) $TXT2 &= $StringMid2 If $StringMid2 = $quotes Then ReDim $SplitArray[$SplitArray[0] + 2] $SplitArray[$SplitArray[0] + 1] = $TXT & $TXT2 $SplitArray[0] = $SplitArray[0] + 1 $X +=1 $I = $X $Y = True ExitLoop EndIf Until StringLen($String) = $X If $Y = False Then ReDim $SplitArray[$SplitArray[0] + 2] $SplitArray[$SplitArray[0] + 1] = StringTrimRight($TXT ,1) $SplitArray[0] = $SplitArray[0] + 1 EndIf $TXT2 = "" Case StringInStr ( $TXT ,$quotes) = False ReDim $SplitArray[$SplitArray[0] + 2] $SplitArray[$SplitArray[0] + 1] = StringTrimRight($TXT ,1) $SplitArray[0] = $SplitArray[0] + 1 EndSelect $TXT = "" EndIf Until StringLen($String) = $I Return $SplitArray EndFunc Edited February 12, 2009 by wolf9228 صرح السماء كان هنا
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