Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To get specific part of a string in c# [closed]

Tags:

People also ask

How do you take a specific part of a string?

The substr() method extracts a part of a string. The substr() method begins at a specified position, and returns a specified number of characters. The substr() method does not change the original string. To extract characters from the end of the string, use a negative start position.

How do you find a specific substring in a string?

The String class provides two accessor methods that return the position within the string of a specific character or substring: indexOf and lastIndexOf . The indexOf method searches forward from the beginning of the string, and lastIndexOf searches backward from the end of the string.

How do you find a specific character in a string C?

The strchr() function finds the first occurrence of a character in a string. The character c can be the null character (\0); the ending null character of string is included in the search.

How do I print part of a string?

printf("%. *s", length, "hello there") will do the trick as well -- the first * just means that a sub- length string will be padded to length characters, which may or may not be the desired behavior.


I have a string

string a = "abc,xyz,wer"; 

Now, I need a part of this string like

string b = "abc"; 

I need everything before the first comma.How shall I get it?