Re: Splitting strings....
Re: Splitting strings....
- Subject: Re: Splitting strings....
- From: Jerry LeVan <email@hidden>
- Date: Fri, 27 Feb 2004 23:36:12 -0500
I don't think that will work...
A semicolon is only a "separator" if it is *not* contained in a quoted
string.
The beginning and end quotes might not be close to the semicolon...
The only way I can think to determine if the semicolon is a legitimate
separator
is to start at the beginning of the string and scan the characters one
at a time.
When a quote (') is found flip the state of "being in a quoted string".
When
a semicolon is encountered if the current state is "not in a quoted
string" then
the semicolon is a separator. I can then extract an appropriate
substring and stick
it into my array of "statements".
I guess I will start the drudge work tomorrow...
The reason for this exercise is that I am working on yet another
postgresql database
browser. ( An enhanced version of BigSQL from the BigNerdRanch people).
Initially I was separating the sql statements via
componentsSeparatedByString method
but then I got interested in PL/pgsql, the postgres "programming"
language. This
extension makes heavy use of semicolons in the definition of functions
(but they
are all contained in a big string).
--Jerry
On Feb 27, 2004, at 11:10 PM, Jonathan Jackel wrote:
1. Make the string mutable.
2. Replace ";" and the other special cases with token strings.
3. Do component's separated by string on what's left.
4. Iterate through the array and replace the tokens with their ";"
counterparts.
Personally, I think you'd be better of with an NSScanner (which, by
the way, does not have to go one character at a time). You can scan
up to the semicolon, check for characters adjacent to the scanner
location, and decide whether to break the string or keep going.
Jonathan
On Feb 27, 2004, at 8:18 PM, Jerry LeVan wrote:
Hi,
I have suddenly developed a need to be able to split a NSString on a
";"
The rub comes in that the semicolon does not count if it is *in* a
quoted string.
Also a string can contain a quote character if it is doubled...
So.
blah blah 'I can''t stand '';'' this ;' foolishness ; any ; more
will split into:
blah blah 'I can''t stand '';'' this ;' foolishness
and
any
and
more
I am not to keen on scanning the string char at a time and keeping
track of the
uncovered semicolons....
Any one tackled this problem before? Is there an elegant solution?
--Jerry
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.