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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:00:53+00:00 2026-06-09T13:00:53+00:00

EDIT: A single string was missing its ( … 8( Sorry for wasting your

  • 0

EDIT: A single string was missing its (… 8( Sorry for wasting your time.

I have a list of strings of the following format:

"Some Text (1234-567890)"

I am trying to use string.Split or Regex.Split to split this around the (, and then pull the preceding text from the first element, and the number text off the second element.

Ex:

string myText = "Some Text (1234-567890)";
string[] myValues = myText.Split('(');
string first = myValues[0]; // should hold "Some Text "
string second = myValues[1]; // should hold "1234-567890)"

Instead what I’m getting, and I get this whether I use string.Split or Regex.Split, is an array containing a single value without the (.

Ex:

string myText = "Some Text (1234-567890)";
string[] myValues = myText.Split('(');
string first = myValues[0]; // has "Some Text 1234-567890)"
string second = myValues[1]; // exception; there is no second value

This also happens if I use Regex.Split. Ex:

string[] myValues = Regex.Split(myText, "\\(");

If I try putting this into a fresh project, it works as I expect. The only difference between the two is that I’m populating the List<string> using Excel interop. I don’t see why that would make a difference.

My actual code looks like this:

const int LOCATION_START = 2;
const int LOCATION_END = 39;
List<string> locationStrings = new List<string>();
for (int row = LOCATION_START + 1; row <= LOCATION_END; row++)
   locationStrings.Add(pExcel.ActiveSheet.ReadValue<string>(row));

List<Tuple<string, string>> locations = new List<Tuple<string, string>>();
foreach (string locationString in locationStrings)
{
   string[] values = Regex.Split(locationString, "\\(");
   locations.Add(Tuple.Create(values[0].Trim(), values[1].Substring(0, 11)));
   // ^ this line throws an exception, because there is only one value, not two
}

Excel.ActiveSheet.ReadValue uses the interop Range function to read a value from an Excel sheet and casts it to a string.

  • 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-06-09T13:00:55+00:00Added an answer on June 9, 2026 at 1:00 pm

    The code that you show works as expected. The only way to get that result is that the string doesn’t contain any starting parenthesis, e.g. contains "Some Text 1234-567890)" and not "Some Text (1234-567890)".

    It’s also possible that you have some unusal character that looks like a starting parenthesis in one environment, but is an unprintable character in another.

    You should check what your strings actually contain when you get them from the Exfel sheet.

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

Sidebar

Related Questions

In a C# windows app I handle HEX Strings. A single HEX string will
I have Ienumerable<string> collection that I want to concatenate into a single string with
I have declared a string in my strings.xml file , and using it in
Say you have something like an ASP.NET ASP:DetailsView to show and edit a single
I have an Android appthat originally posted some strings in json format to a
As is described at Microsoft Site ,String.Format arranges some String Variables into a single
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
So I have model with an association and I'm using a single form with
I have an Object with (de-)serializes its configuration via system.xml.serializer The config is in

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.