[newbie] Split a string

G

Guest

Hi,

I've just learned how to split a string (guess what, the Split function ;),
but as a newbie I'm stucked on a different problem:

I'd only wanted the function to split the string at a specific position
(e.g. ";") when the surrounding string is NOT in quotation marks, like that:

abc;def -> split into 2 strings ('abc' and 'def')
"abc;def";ghi -> split into 2 strings ('abc;def' and 'ghi') as well

Can anyone give me a hint on how to do that?

Thanks for any help
Peter
 
M

Mr Newbie

abc;def -> split into 2 strings ('abc' and 'def')
"abc;def";ghi -> split into 2 strings ('abc;def' and 'ghi') as well

In the second example, you have one within quotes and the second without.
You also have a seperator character inside the first string of example 2.

Can you please be specific about the data strings you are working on,
without credible and accurate information, it is hard to give the same in an
answer
 
J

Jason Sobell

Hi,

I've just learned how to split a string (guess what, the Split function ;),
but as a newbie I'm stucked on a different problem:

I'd only wanted the function to split the string at a specific position
(e.g. ";") when the surrounding string is NOT in quotation marks, like that:

abc;def -> split into 2 strings ('abc' and 'def')
"abc;def";ghi -> split into 2 strings ('abc;def' and 'ghi') as well

Can anyone give me a hint on how to do that?

Thanks for any help
Peter

Look at the REGEX functions in .NET. I know it's a daunting system to begin
with, but it allows you to do this sort of thing easily.
Look at "RegexDesigner.NET" here: http://www.sellsbrothers.com/tools/
This will probably answer all of your questions.

Cheers,
Jason
 
J

Jason Sobell

In the second example, you have one within quotes and the second without.
You also have a seperator character inside the first string of example 2.

Can you please be specific about the data strings you are working on,
without credible and accurate information, it is hard to give the same in an
answer

Ouch. I think he did explain what he wanted. The separator is deliberately
inside the quotes, and he's asking for parsing of quoted strings in a
character delimited file.

Cheers,
Jason
 
L

Lloyd Dupont

I would use regular expression.

Every time I stop using them I forget everything about them so I can't quite
help you more on that.
But suffice to say there is heaps of community material on them and they are
not that difficult to comprehend.
 
C

Chad Smith

Hi,

I've just learned how to split a string (guess what, the Split function ;),
but as a newbie I'm stucked on a different problem:
Peter,

String.Split is a very simplistic class and cannot handle more than simple
character matching, fortunately the Regular Expression library in .NET offers
a Split method and should be more than capable of meeting your match
criteria, you may need to study a regular expression reference for a while to
get that, or ask somebody to create a regex for you.


http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.split

Regards,
Chad Smith
 
M

Mr Newbie

Thats really funny because Im exactly the same, the syntax for regex is so
akward that its impossible to remember how the switched work unless you use
it all the time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top