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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:18:31+00:00 2026-06-10T10:18:31+00:00

I have the following code string tString; int flNum; string flLeg; tString = 25664-A;

  • 0

I have the following code

  string tString;
  int flNum;
  string flLeg;

  tString = "25664-A";

I need to get tString into two variables, flNum and flLeg.
My desired results are- flNum = 25664 flLeg = A

My attempt was –

 flNum = Convert.ToInt32(tString.Substring(tString.IndexOf("-") - 1));
 flLeg = tString.Substring(tString.IndexOf("-") + 1, 1);

But it errors out on me. Any suggestions on how to change this code in order to get my desired results?

Thanks for you assistance.

  • 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-10T10:18:33+00:00Added an answer on June 10, 2026 at 10:18 am

    You could simply use the string.Split() method.

    string[] result = tString.Split('-')
    int flNum = Convert.ToInt32(result[0]);
    string flLeg = result[1];
    

    In your code, you get an error because, for the first substring, you need to pass a starting point and a length

    flNum = Convert.ToInt32(tString.Substring(0, tString.IndexOf("-")));  
    

    You find correctly the position of the dash, but this position is passed as the starting point to substring but there is no number starting from the pos passed, so the conversion fails.

    (And remove the – 1 for the length because this is…. well a length not a position)

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

Sidebar

Related Questions

I have the following code: String website = http://www.somewebsite.com/; Document doc = Jsoup.connect(website).get(); Elements
I have the following code : std::string Utils::get() { std::string result; result.append(1, 'x'); result.append(1,
I have the following code: delegate int doStuffDel(int instanceNo, int sleepTime, int repeatCount); string
I have the following code: string acctStatus = account.AccountStatus.ToString(); if (!SettableStatuses().Any(status => status ==
I have the following code string three() { return three; } void mutate(string& ref)
I have the following code: String serviceType; ServiceBrowser tmpBrowser; for (String playerName: players) {
I have the following code: string[] firstArray = { bla bla, bla bla, bla
Ok so I have the following code: string numbers = File.ReadAllText(numbers.txt); StringSplitOptions.RemoveEmptyEntries); List<string> List
Follow up to this question . I have the following code: string[] names =
I have the following code: private String foo; public void setFoo(String bar) { foo

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.