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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:20:16+00:00 2026-05-27T12:20:16+00:00

How can i split the following string into Key-Value Pair / Hash table …

  • 0

How can i split the following string into Key-Value Pair / Hash table …

"Id=1000;Name=xyzabc;DB=1.2.3.4;DBUserName=admin;DBPassword"

I know it can be done by using string.Split() (One with ‘;’, and then each result with ‘=’).
I am looking for an easy and efficient way of doing it.

In short, instead of string manipulation is there an efficient way to convert the above highlighted text to access the value something like this…

someObject["Id"];//It should return 1000 
someObject["Name"];//It should return xyzabc 
someObject["DB"];//It should return xyzabc ..............

Does framework has any build in class to do it?

eg: The SQLConnectionBuilder will split the DBName, UserName, Password into its property, if we assign a connectionstring to the SQLConnectionBuilder

  • 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-27T12:20:17+00:00Added an answer on May 27, 2026 at 12:20 pm

    Taking your example about DbConnectionStringBuilder, if you look at the internals you’ll find a method called DbConnectionOptions.GetKeyValuePair and it is not for the faint of heart. Skip that, and try something easy:

    string input = "Id=1000;Name=xyzabc;DB=1.2.3.4;DBUserName=admin;DBPassword";
    
    var kvp = input.Split(';')
        .Select(s => s.Split('='))
        .ToDictionary(s => s.First(), s => s.Last());
    

    You’ll get a Dictionary output that looks something like this:

    Key=Id, Value=1000
    Key=Name, Value=xyzabc
    Key=DB, Value=1.2.3.4
    Key=DBUserName, Value=admin
    Key=DBPassword, Value=DBPassword
    

    Of course, if you have duplicate keys in your string then a dictionary won’t work. You might consider writing your own extension like .ToKeyValuePair(). I’m not quite sure about how to fix the key = value when you don’t provide a value, but I’m too tired to think very hard about it.

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

Sidebar

Related Questions

How can I split a string such as Mar10 into Mar and 10 in
I need to split long string into a array with following constrains: The input
I'm trying to split a string into two different words. I have the following
How can I split a String by Unicode range in Ruby. I wanted to
How can I take a multi-dimensional array like the below, and split it into
I am using the String.Split() method in C#. How can I put the resulting
Inorder to split the string i have used the following code. $string = -sev*yes-sev1*no-sev2*yes;
Consider the following String : 5|12345|value1|value2|value3|value4+5|777|value1|value2|value3|value4?5|777|value1|value2|value3|value4+ Here is how I want to split string,
say I have the following string: "Hello there. My name is Fred. I am
I want to split this line: string line = First Name ; string ;

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.