shanikawm
asked on
C Programing - get substring between two chars
I have strings like follow.
char str1[]="455:2355;";
char str2[]="317:5569;";
char str2[]="213:8254;";
.....
What is the easiest way to get the integer value between ":" and ";"?
I could get the first one (i.e. 455,317,213 ...) using atoi(str1).
I'm using gcc version 3.3.2
char str1[]="455:2355;";
char str2[]="317:5569;";
char str2[]="213:8254;";
.....
What is the easiest way to get the integer value between ":" and ";"?
I could get the first one (i.e. 455,317,213 ...) using atoi(str1).
I'm using gcc version 3.3.2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you can use strtok to tokenize the string, and then use atoi to convert each token to its corresponding integer value.
char str1[] = "455:2355;";
string result=str1.substring(str1 ,str1.char at(':') , str1.charat(';') - str1.charat(':') );
convert result to integer
string result=str1.substring(str1
convert result to integer
@divyeshhdoshi : this is about C ;)
ASKER
Great. Thanks.
Open in new window