+ 4
How to print last n characters of a string?
6 Antworten
+ 7
thanks ~ swim ~ 😅😅😅😅
+ 5
In C :
const char * s = ...;
unsigned size = strlen(s);
unsigned n = ...;
printf("%s\n", s + (size - n));
In c++ (optimized) :
std::string s = ...;
unsigned n = ...;
std::cout << (s.c_str() + (s.size() - n)) << std::endl;
+ 3
in which language?
string s =...;
cout << s.substr(s.length()-n,n);
works in c++
https://code.sololearn.com/c3qrJtjYUG2Z/?ref=app
+ 3
be more specific with your language..
but heres a global tip...
reverse the string..
then strip n number of characters of it from the front...