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.
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With