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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:55:52+00:00 2026-05-23T07:55:52+00:00

Q: I want to get sub strings according to some sign like – .

  • 0

Q:

I want to get sub strings according to some sign like - .

EX:

if i have string like this :

saturday-sa-0-

and i wanna to get:

saturday

sa

0

I search and find the following method:

string substring = name.Split('-')[i];

my code block sample:

foreach (string name in q)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        string substring = name.Split('-')[i];
                    }
                }

but i read the comments about the performance drawbacks when i have a long string ..
my question is: Is there any way to substring according to specific sign and not affect badly on the performance code?

  • 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-23T07:55:53+00:00Added an answer on May 23, 2026 at 7:55 am

    First, you should execute the Split operation only once. I.e., instead of

    some loop {
        ...
        string substring = name.Split('-')[i];
        ...
    }
    

    use

    string[] substrings = name.Split('-');
    some loop {
        ...
        string substring = substrings[i];
        ...
    }
    

    Second, don’t worry about the performance of Strint.Split too much unless

    • you have a real, measurable performance problem and
    • you know that String.Split is the culprit.

    For example, if you have some database operation that takes 1 second, it does not really matter if the subsequent Split operation takes 0.001 or 0.002 seconds.


    EDIT: Regarding the code in your comment: You can refactor

    foreach (string name in q) {
        for (int i = 0; i < 3; i++) {
           string substring = name.Split('-')[i]; 
           // do something with substring
        }
    }
    

    to

    foreach (string name in q) {
        string[] substrings = name.Split('-'); 
        for (int i = 0; i < 3; i++) {
           string substring = substrings[i]; 
           // do something with substring
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a string like this . var url=http://localhost/elephanti2/chaink/stores/stores_ajax_page/5/b.BusinessName/asc/1/11 i want to get substrings
I have image data and i want to get a sub image of that
I have a string: s = <aaa>bbb</ccc> I want to get aaa and bbb
I want to get an entity with its sub-properties. How can I do that
I want to get started doing some game development using Microsoft's XNA. Part of
I want to get the MD5 Hash of a string value in SQL Server
I want to get my databases under version control. I'll always want to have
I have created some sample ontology in protege.According to my ontology there is a
This is for basic HTML/PHP pages, no query strings, etc.. I have searched high
I'm trying to get pyparsing to extract a sub-string consisting of a variable number

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.