Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI My search string is like
string str="router configuration management" and framework and technology.
Iam splitting the string based on whitespace.
splitting the string like
"router configuration management"
and
framework
and
technology.
when iam splitting the string between the double quotation is also splitting like
router
configuration
management
but i don't want to split the word between double quotations.
It has to be search like one word.
How to do that????
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jun-11 2:33am    
Excuse me, could you make it more clear.
Please give examples in the following ways: 1) original string, 2) correctly split string, 3) optionally -- incorrectly split string due to the limitation of string.Split, all with explanations and different variants causing difficulty, if applicable.

Thank you.
--SA

1 solution

As far as I can understand, this should be the same algorithm .NET uses to split a command line if it contains quotation marks. It is not so easy to do.

If so, you can download my code which is published on CodeProject and is very well tested. I had to develop this function to be able to test command line parsing effectively without re-starting the test application many times (and actually found and fixed a number of bugs in a short period of time).

To locate this code, please see my article Enumeration-based Command Line Utility[^] and download the source code.

How to locate this function? Let's see… In the article, see the section "6. CommandLine Testing", it explains the utility static class SA.Universal.Utilities.CommandLineSimulationUtility. Read about it and locate this class in the source code.

Please try it out and tell me if this is what you needed.

—SA
 
Share this answer
 
Comments
CS2011 16-Jun-11 3:00am    
Very useful link.my 5
Sergey Alexandrovich Kryukov 16-Jun-11 3:02am    
Thank you. This article is quickly becoming popular during last 2-3 days; I don't know what happened, hardly my update or 2-3 self-references like this one.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900