Manipulate string with Substring

Asked

Viewed 25 times

0

I’m trying to manipulate a string

I’m running the code:

string oldString = ",,,,,1001,1002,1003,1004,1005,1006,1007,1008";
string newString = oldString.Substring(oldString.IndexOf("1"));

I want the new string to be: "1001,1002,1003,1004,1005,1006,1007,1008"

But it is returning: ",1003,1004,1005,1006,1007,1008".

  • 1

    This code should work: https://repl.it/repls/VillainousTallFormat

1 answer

2


You can do it using Trim instead of substring, like this:

string oldString = ",,,,,1001,1002,1003,1004,1005,1006,1007,1008";
string newString = oldString.TrimStart(',');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.