Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 46825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:01:35+00:00 2026-05-10T16:01:35+00:00

I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to

  • 0

I have string like this

 /c SomeText\MoreText 'Some Text\More Text\Lol' SomeText 

I want to tokenize it, however I can’t just split on the spaces. I’ve come up with somewhat ugly parser that works, but I’m wondering if anyone has a more elegant design.

This is in C# btw.

EDIT: My ugly version, while ugly, is O(N) and may actually be faster than using a RegEx.

private string[] tokenize(string input) {     string[] tokens = input.Split(' ');     List<String> output = new List<String>();      for (int i = 0; i < tokens.Length; i++)     {         if (tokens[i].StartsWith('\''))         {             string temp = tokens[i];             int k = 0;             for (k = i + 1; k < tokens.Length; k++)             {                 if (tokens[k].EndsWith('\''))                 {                     temp += ' ' + tokens[k];                     break;                 }                 else                 {                     temp += ' ' + tokens[k];                 }             }             output.Add(temp);             i = k + 1;         }         else         {             output.Add(tokens[i]);         }     }      return output.ToArray();             } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:01:36+00:00Added an answer on May 10, 2026 at 4:01 pm

    The computer term for what you’re doing is lexical analysis; read that for a good summary of this common task.

    Based on your example, I’m guessing that you want whitespace to separate your words, but stuff in quotation marks should be treated as a ‘word’ without the quotes.

    The simplest way to do this is to define a word as a regular expression:

    ([^'^\s]+)\s*|'([^']+)'\s* 

    This expression states that a ‘word’ is either (1) non-quote, non-whitespace text surrounded by whitespace, or (2) non-quote text surrounded by quotes (followed by some whitespace). Note the use of capturing parentheses to highlight the desired text.

    Armed with that regex, your algorithm is simple: search your text for the next ‘word’ as defined by the capturing parentheses, and return it. Repeat that until you run out of ‘words’.

    Here’s the simplest bit of working code I could come up with, in VB.NET. Note that we have to check both groups for data since there are two sets of capturing parentheses.

    Dim token As String Dim r As Regex = New Regex('([^''^\s]+)\s*|''([^'']+)''\s*') Dim m As Match = r.Match('this is a ''test string''')  While m.Success     token = m.Groups(1).ToString     If token.length = 0 And m.Groups.Count > 1 Then         token = m.Groups(2).ToString     End If     m = m.NextMatch End While 

    Note 1: Will’s answer, above, is the same idea as this one. Hopefully this answer explains the details behind the scene a little better 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It sounds like you may want to use findall rather… May 11, 2026 at 2:59 pm
  • added an answer Asynchronous methods in the .NET classes follows the the BeginSomeAction()… May 11, 2026 at 2:59 pm
  • added an answer There doesn't appear to anyway in native C# to do… May 11, 2026 at 2:59 pm

Related Questions

I'm using a string builder to build some SQL Scripts. I have a few
Hello I have a chunk of memory (allocated with malloc()) that contains bits (bit
I'm a newbie to LINQ in C# and am using it to read in
I'm still playing around with xml. Now I have a file that looks like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.