Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I find second occurrences "-" in string and split
I need to get only:myFileName-12345678


string[] tokens = originalFileName.Split(new char[] {'-', '.'});

After that, re-compose the output string fragment at your liking. Prefer string.Format over string concatenation, for example:

int tokenLength = tokens.Length;
if (tokenLength > 2)
   myNewFileName = string.Format("{0}-{1}.{2}",
        tokens[0], tokens[1], tokens[tokenLength - 1]);

Share this answer
You can take the substring using Substring method and define the starting point based on the value returned by IndexOf('-').
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900