Substring after character C#

Asked

Viewed 237 times

-5

Good Afternoon

string nr = ABC:1

I’d like to take the number after ":" as I would?

nr = nr.substring(...);

Expected result:

for nr = ABC:50

nr = 50;

for nr = LKfasEWF:5039

nr = 5039
  • 3

    Explain better, you have a string any with any text, within this text can/should have a : and you want everything you have after it? You may not have the :? Can you have more than one? What to do in these cases? If you have space what to do with it? Does it include or not? To program first you need to understand the problem, and specify every detail.

1 answer

-1


To do this, just take the position the/string character is in, and then use the substring starting from that+1 position. Follow example.

string nr = "ABC: 1";

int posicaoCaractere = nr.IndexOf(": ");

nr = nr.Substring(posicaoCaractere+1);

MessageBox.Show(nr);

Browser other questions tagged

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