M
M
Mikhail2017-09-25 12:45:12
C++ / C#
Mikhail, 2017-09-25 12:45:12

C#. How to remove the part of a string that comes after the last character, such as a comma?

Yes:
string aaa = "Hi, what are you doing, how are you";
Needed:
string aaa = "Hi, what are you doing";
string bbb = "how are you";

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Pavlov, 2017-09-25
@TheMaxai

string aaa = "Привет, что делаешь, как дела";
int pos = aaa.LastIndexOf(',');
string bbb = aaa.Substring(pos);
aaa = aaa.Substring(0, pos);

D
DarkByte2015, 2017-09-25
@DarkByte2015

string aaa = "Привет, что делаешь";
string bbb = aaa.Split(',').Last();

F
Fat Lorrie, 2017-09-25
@Free_ze

remove the part of the string that comes after the last character

aaa = aaa.Substring(0, aaa.LastIndexOf(',') + 1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question