Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
GeneralRe: best ways for multi-user application Pin
hamid_m19-Apr-07 10:52
hamid_m19-Apr-07 10:52 
GeneralRe: best ways for multi-user application Pin
Dave Kreskowiak19-Apr-07 15:48
mveDave Kreskowiak19-Apr-07 15:48 
GeneralRe: best ways for multi-user application Pin
hamid_m19-Apr-07 19:49
hamid_m19-Apr-07 19:49 
GeneralRe: best ways for multi-user application Pin
Dave Kreskowiak20-Apr-07 2:01
mveDave Kreskowiak20-Apr-07 2:01 
Questionc # xml validation on 1.0 [modified] Pin
FilNC19-Apr-07 7:54
FilNC19-Apr-07 7:54 
QuestionTokenize which ignores quotes and parantheses etc. Pin
peterchen19-Apr-07 7:35
peterchen19-Apr-07 7:35 
AnswerRe: Tokenize which ignores quotes and parantheses etc. Pin
Dmitry Khudorozhkov19-Apr-07 13:56
Dmitry Khudorozhkov19-Apr-07 13:56 
AnswerRe: Tokenize which ignores quotes and parantheses etc. Pin
Judah Gabriel Himango20-Apr-07 4:00
sponsorJudah Gabriel Himango20-Apr-07 4:00 
Hey peterchen. Looks like Dmitry has pointed you to an article that may work.

In case it doesn't work, here's something I coded up. I spent a good 20 minutes or so trying 3 different solutions. This one seems to work best, although I haven't run it through any kind of rigorous testing. It uses C# 2's iterators for great performance -- it only does work when you ask for results. Here it is:

public IEnumerable<string> Tokenize(string input, char seperator)
     {
         int lastSeperatorIndex = 0;
         int openSingleQuoteCount = 0;
         int openParenthesisCount = 0;

         for (int i = 0; i < input.Length; i++)
         {
             char character = input[i];
             if (character == '(')
             {
                 openParenthesisCount++;
             }
             else if (character == ')' && openParenthesisCount > 0)
             {
                 openParenthesisCount--;
             }
             else if (character == '\'')
             {
                 openSingleQuoteCount = (openSingleQuoteCount == 0) ? openSingleQuoteCount + 1 : openSingleQuoteCount - 1;
             }
             else if (character == seperator && openParenthesisCount == 0 && openSingleQuoteCount == 0)
             {
                 yield return input.Substring(lastSeperatorIndex, i - lastSeperatorIndex + 1).Trim(seperator);
                 lastSeperatorIndex = i;
             }

             // If we're at the end and we've got some characters since our last yield,
             // yield the rest of the string.
             if (i == input.Length - 1 && i != lastSeperatorIndex)
             {
                 yield return input.Substring(lastSeperatorIndex, i - lastSeperatorIndex + 1).Trim(seperator);
             }
         }
     }


Putting in this string: "Hello, 'World,Worlds', something(goo,gambas), blahFoo(inner(double, inner), outer)"

Results in "Hello", "'World,Worlds'", "something(goo,gambas)", "blahFoo(inner(double, inner), outer)".

For what it's worth, I bet LINQ would let us write a little query on the string to accomplish the same thing, only in about 3 or 4 lines of code.





Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Virginia Tech Shootings, Guns, and Politics
The apostle Paul, modernly speaking: Epistles of Paul

Judah Himango


GeneralRe: Tokenize which ignores quotes and parantheses etc. Pin
peterchen20-Apr-07 11:51
peterchen20-Apr-07 11:51 
GeneralRe: Tokenize which ignores quotes and parantheses etc. Pin
Judah Gabriel Himango22-Apr-07 8:21
sponsorJudah Gabriel Himango22-Apr-07 8:21 
QuestionExecuting exe from exe, closing the 1st one without closing he 2nd!!! Pin
Adeel Chaudhry19-Apr-07 7:02
Adeel Chaudhry19-Apr-07 7:02 
AnswerRe: Executing exe from exe, closing the 1st one without closing he 2nd!!! Pin
Tarakeshwar Reddy19-Apr-07 7:10
professionalTarakeshwar Reddy19-Apr-07 7:10 
GeneralRe: Executing exe from exe, closing the 1st one without closing he 2nd!!! Pin
Adeel Chaudhry19-Apr-07 7:14
Adeel Chaudhry19-Apr-07 7:14 
QuestionSystem.Type from class name string, interface support and instantiation Pin
peterchen19-Apr-07 6:54
peterchen19-Apr-07 6:54 
AnswerRe: System.Type from class name string, interface support and instantiation Pin
hamid_m19-Apr-07 7:41
hamid_m19-Apr-07 7:41 
AnswerRe: System.Type from class name string, interface support and instantiation [modified] Pin
Kythen20-Apr-07 10:57
Kythen20-Apr-07 10:57 
GeneralRe: System.Type from class name string, interface support and instantiation Pin
peterchen20-Apr-07 11:44
peterchen20-Apr-07 11:44 
QuestionSimple question Does any have a nice control derived from IToolboxService? Pin
Christopher Stratmann19-Apr-07 6:28
Christopher Stratmann19-Apr-07 6:28 
QuestionMaster/details Pin
hadad19-Apr-07 5:26
hadad19-Apr-07 5:26 
AnswerRe: Master/details Pin
Dmitry Khudorozhkov19-Apr-07 14:12
Dmitry Khudorozhkov19-Apr-07 14:12 
QuestionIList implementation with change event? Pin
peterchen19-Apr-07 5:20
peterchen19-Apr-07 5:20 
Answer[sort of solved] Pin
peterchen19-Apr-07 6:59
peterchen19-Apr-07 6:59 
AnswerRe: IList implementation with change event? Pin
Leslie Sanford19-Apr-07 8:53
Leslie Sanford19-Apr-07 8:53 
GeneralRe: IList implementation with change event? Pin
peterchen19-Apr-07 13:29
peterchen19-Apr-07 13:29 
QuestionGenerate a form by using form name as string Pin
ayca19-Apr-07 5:02
ayca19-Apr-07 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.