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 558993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:11:25+00:00 2026-05-13T12:11:25+00:00

please help me this problem. I want to split -action=1 to action and 1.

  • 0

please help me this problem.
I want to split “-action=1” to “action” and “1”.

string pattern = @"^-(\S+)=(\S+)$";
Regex regex = new Regex(pattern);
string myText = "-action=1";
string[] result = regex.Split(myText);

I don’t know why result have length=4.

result[0] = ""
result[1] = "action"
result[2] = "1"
result[3] = ""

Please help me.

P/S: I am using .NET 2.0.

Thanks.

Hello, I tested with string: @”-destination=C:\Program Files\Release” but it have inaccurate result, I don’t understand why result’s length = 1. I think because it has a white space in string.

I want to split it to “destination” & “C:\Program Files\Release”

More info: This is my requirement:
-string1=string2 -> split it to: string1 & string2.
In string1 & string2 don’t contain characters: ‘-‘, ‘=’, but they can contain white space.

Please help me. Thanks.

  • 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-13T12:11:25+00:00Added an answer on May 13, 2026 at 12:11 pm

    Try this (updated to add Regex.Split):

    string victim = "-action=1";
    string[] stringSplit = victim.Split("-=".ToCharArray());
    string[] regexSplit = Regex.Split(victim, "[-=]");
    

    EDIT: Using your example:

    string input = @"-destination=C:\Program Files\Release -action=value";
    foreach(Match match in Regex.Matches(input, @"-(?<name>\w+)=(?<value>[^=-]*)"))
    {
        Console.WriteLine("{0}", match.Value);
        Console.WriteLine("\tname  = {0}", match.Groups["name" ].Value);
        Console.WriteLine("\tvalue = {0}", match.Groups["value"].Value);
    }
    Console.ReadLine();
    

    Of course, this code have issues if your path contains - character

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

Sidebar

Related Questions

I'm helpless on regular expressions so please help me on this problem. Basically I
I have a problem and I couldn't solve it.please help me. I have two
hey all.i'm newbie at this problem.i have this data in table result: item range_code
i have an old string say oldString=abc-2 i want to change it to abc-3
I want to substitute a certain filed of the text while keeping the same
I am using facebook graph Api for my application where i want the data
I have client which has a problem with printing from JAVA applications, using old
I have created a music application in iphone . i want to integrate twitter
I have a column with datetime datatype called 'updated_at' in a mysql table,where i
I am using the windows API (in C++) to create a windows application. Now,

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.