Go Down

Topic: Extracting substring of variable length (Read 1 time) previous topic - next topic

overrider

Greetings,

i am looking for a solution to reliably extract a phone number of variable length from a String.

The String looks like this, with the part i need to extract being +8613920001234 :
Code: [Select]

+CMGR: "REC UNREAD","+8613920001234","","12/12/13,15:08:55+50"


What i have tried so far is this quite nasty piece, which works kind of but only when specifying the length of the number i need:
Code: [Select]

(sms.substring(sms.indexOf("READ\",\"")+7,sms.indexOf("READ\",\"")+21)).toCharArray(phonenumber_new,20);


I guess whats needed is to somehow extract everything between READ"," and the following ",. I would be most grateful for any insights or approaches.

Peace and have a good day.


PaulS

Quote
Does this help

Not when using a String. Which OP should not be.

dhenry

Easy:

1) zero the target string;
2) search for '+' til the end of the source string;
3) from there, copy to '"', or end of the source string.
4) done.

Riva


Quote
Does this help

Not when using a String. Which OP should not be.

Ah, so String is based on string. I assumed they were different as peoples have highlighted an OP's post asking when they say string did they mean String or string.

Go Up