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

  • Home
  • SEARCH
  • 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 7663555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:05:01+00:00 2026-05-31T14:05:01+00:00

I cannot believe I am having trouble with this following string String filter =

  • 0

I cannot believe I am having trouble with this following string

String filter = "name=Default;pattern=%%;start=Last;end=Now";

This is a short and possibly duplicate question, but how would I split this string to get:

string Name = "Default";
string Pattern = "%%" ;
string start = "Last" ;
string end = "Now" ;

Reason why I ask is my deadline is very soon, and this is literally the last thing I must do. I’m Panicking, and I’m stuck on this basic command. I tried:

pattern = filter.Split(new string[] { "pattern=", ";" },
                       StringSplitOptions.RemoveEmptyEntries)[1]; //Gets the pattern
startDate = filter.Split(new string[] { "start=", ";" },
                         StringSplitOptions.RemoveEmptyEntries)[1]; //Gets the start date

I happen to get the pattern which I needed, but as soon as I try to split start, I get the value as “Pattern=%%”

What can I do?

Forgot to mention
The list in this string which needs splitting may not be in any particular order . this is a single sample of a string which will be read out of a stringCollection (reading these filters from Properties.Settings.Filters

  • 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. Editorial Team
    Editorial Team
    2026-05-31T14:05:02+00:00Added an answer on May 31, 2026 at 2:05 pm

    The start date ends up at the thrird position in the array:

    startDate = filter.Split(new string[] { "start=", ";" }, StringSplitOptions.RemoveEmptyEntries)[2];
    

    Instead of splitting the string once for each value, you might want to split it into the separate key-value pairs, then split each pair:

    string[] pairs = filter.Split(';');
    string[] values = pairs.Select(pair => pair.Split('=')[1]).ToArray();
    
    string name = values[0];
    string pattern = values[1];
    string start = values[2];
    string end = values[3];
    

    (This code of course assumes that the key-value pairs always come in the same order.)

    You could also split the string into intersperced array, so that every other item is a key or a value:

    string[] values = filter.Split(new string[] { "=", ";" }, StringSplitOptions.None);
    
    string name = values[1];
    string pattern = values[3];
    string start = values[5];
    string end = values[7];
    

    Edit:

    To handle key-values in any order, make a lookup from the string, and pick values from it:

    ILookup<string, string> values =
      filter.Split(';')
      .Select(s => s.Split('='))
      .ToLookup(p => p[0], p => p[1]);
    
    string name = values["name"].Single();
    string pattern = values["pattern"].Single();
    string start = values["start"].Single();
    string end = values["end"].Single();
    

    You can use SingleOrDefault if you want to support values being missing from the string:

    string name = values["name"].SingleOrDefault() ?? "DefaultName";
    

    The lookup also supports duplicate key-value pairs. If there might be duplicates, just loop through the values:

    foreach (var string name in values["name"]) {
      // do something with the name
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply cannot believe this is quite so hard to determine. Even having read
I am having trouble identifying a problem on Android TimerTask (I believe) that is
I'm having trouble within a block of code that I believe is related to
I'm lead to believe that I cannot count on the order of items added
The commons FileUtils look pretty cool, and I can't believe that they cannot be
I cannot understand how this is possible. Please help!! I have an app with
I cannot get a two-way bind in WPF to work. I have a string
Um, this might sound a bit weird. We were having some problems with a
I am using Aptana Studio 3 and having trouble creating a rails project in
I am having trouble gaining access to FileMaker Pro 11 data through the ODBC

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.