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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:55:32+00:00 2026-05-24T12:55:32+00:00

I use asp.net 4 and c#. I have a string: string original = hi-this-is-a-string-15

  • 0

I use asp.net 4 and c#.

I have a string:

string original = "hi-this-is-a-string-15"

Please note the last 3 digit from right -15

Now the same string but with more digit after the last dash

hi-this-is-a-string-9999

Please note the last 5 letters from right -9999

I need a RegEx or another solution which allow me to make a sub-selection in string original on any digit following the last dash ex: -15 or -999.

The Role should be flexible to detect any digit variable length after the last dash ex: -1 or -5656565656565...

At the end of the process I should have:

string original = "hi-this-is-a-string-15"
string cropped = "hi-this-is-a-string"
string suffix = "-15"

Any idea how to do it? Thanks for your help on this.

My original code (Generates error):

string original = "hi-this-is-a-string-15";
int l = original.Length;
int i = original.LastIndexOf("-");
string sub = original.Substring(i, l);

error: Index and length must refer to a location within the string. Parameter name: length 
  • 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-24T12:55:33+00:00Added an answer on May 24, 2026 at 12:55 pm

    You can get the index of last occurrence and return the sub string form that index like.

    var index = original.LastIndexOf('-');
    var suffix = original.Substring(index);
    var crop = original.Substring(0, index);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few controls that inherit from ASP.NET buttons and use onserverclick .
I have a string (coming from ASP.NET) which contains one or more placeholders. In
I have tried to use ASP.NET MVC for a while, then I face a
I work on a web game , I use asp.net mvc, linqtosql. I have
I have found ASP.Net PageMethods very handy and easy to use, but I have
Suppose you have two seperate ASP.NET Web Application projects that both need to use
I have an ASP.net project I'm looking at and they want to use MySQL.
I have some ASP.NET Master Pages located in one assembly. I need to use
I have an ASP.NET linkbutton control on my form. I would like to use
I am trying to use page methods in my asp.net page. I have enable

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.