booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 07 Oct 2011 06:44 PM |
| What is the equivalent of string.sub? |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2011 06:48 PM |
I'm not sure, you should check the documentation on cplusplus DOT com. Although there might not be a such function, in which case, writing one yourself would probably be easy.
But, are you using C or C++? If you're using C++, you can use the string library. If you're on C, you need to use tables that contain characters. So it's not the same for C and C++... |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Oct 2011 06:54 PM |
char t = ['h', 'e', 'l', 'l', 'o']
or sumthin liek dat |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2011 06:56 PM |
Well, I guess
("HI").Substring(Start, End);
Ex:
cout >> ("Hello").Substring(2, 1); // "l" |
|
|
| Report Abuse |
|
|
| |
|
|
| 07 Oct 2011 07:00 PM |
For a std::string, the method would be substr. So:
std::string HelloWorld ("Hello World!"); std::cout << HelloWorld.substr(0, 5); |
|
|
| Report Abuse |
|
|
|
| 07 Oct 2011 07:01 PM |
getting the end of a string with char arrays in C:
#include stdio.h
int main() { char* original = "Hello world!"; char* substring = (original+6); printf(substring); return 0; }
> world! |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
| |
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 07 Oct 2011 07:19 PM |
"If you're on C, you need to use tables that contain characters."
Wat? You mean character arrays?
Anyways, in C you could do simple pointer mathz to replicate what substr does |
|
|
| Report Abuse |
|
|