i have a string and i want to get, for example, the position of the last (.) in the string, or whatever char i want to check, but untill now i just get a headeach.
thanks
To get the last N characters of a string, call the slice method on the string, passing in -n as a parameter, e.g. str. slice(-3) returns a new string containing the last 3 characters of the original string.
The strrchr() function in C/C++ locates the last occurrence of a character in a string. It returns a pointer to the last occurrence in the string. The terminating null character is considered part of the C string. Therefore, it can also be located to retrieve a pointer to the end of a string.
Simple approach should be taking Substring of an input string. var result = input. Substring(input. Length - 3);
string lastN(string input)
{
return input.substr(input.size() - n);
}
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