Read characters between " ".

Hi i'm wondering how can i read something taht is between quotation marks..for ex:

+CMT: "+112233445566","","19/02/08,15:54:59-12"
get number

this is a text message i receive in my module sim and that's what the monitor shows..
i now if i want to extract the content between the " ", i do this:

int pos = message.indexOf("+CMT: ");
Sender_SMS = message.substring(pos+7,pos+21);

that works great, but depending on the company they use 13 numbers ( including + and code country) and others use 14 numbers..

that is my problem, because is not the same 13 than 14 to extract, with 13 would be :

"+112233445566" and the xtraction: +112233445566

but with 14:"+1122334455667" and the xtraction: +112233445566, missing one number, so i wouldn't be able to send sms back to the Sender_SMS...

Here is what i want/try to do:

how can i search for the first " and count the characters to the second? so then i'll know if its a 13 number o 14...

i can't imagine a different way to do it...

how can i search for the first "

indexOf()

and count the characters to the second?

Same function.

When you know that a " is in position n and one is in position m, it is easy, although unnecessary, to calculate the number of characters between them.

Hi PaulS, the problen is that messages are sent with different companies, so its not possible to change the code depending on that situation..
so i beed to find a way to count bettween the " " everytime an sms arrives to be sure about the number to respond the sms...

fernqn:
Hi PaulS, the problen is that messages are sent with different companies, so its not possible to change the code depending on that situation..
so i beed to find a way to count bettween the " " everytime an sms arrives to be sure about the number to respond the sms...

You can do that, or you can let the substring() method count the characters. You'll need to use substring, anyway, so let it do the counting.

Ok but thats my problem i dont know how to use substring() to count the characters between the both " "…

Use 'indexOf()' again to find the second occurrence of ". See:indexOf() - Arduino Reference

I dont get it...i need the number between the" ", so i know i can do that if the number change size?

I can find the first " with pos etc..then with pos1 i get the second " etc...in the middle could be a number with 13 or 14 digits...how can i count that?

If the first character is at position 13 and the second is at position 22, you can determine the number of characters in between without needing to take your shoes off, can't you?

Sory PaulS you didnt get it...i dont know i its my fault or yours..i said the number inside the two first " " can be 13 or 14 depending on the company from you send the sms..could be 13 or 14..hiw can i respond that sms if i dont know the number exactly? If the number 13 characters long and the code is programmed for 13 its ok...but what happend if the code is programmed for 13 characters and i receive a 14 characters long phone number? I wouldn't be able to respond..would be an error in the at command cmgs...

Read this again:

gfvalvo:
Use 'indexOf()' again to find the second occurrence of ".

If you know where the 1st occurrence is and where the second occurrence is, then you can surely use substring() to extract the characters in between (regardless of whether there's 13, 14, or 50).

i know where the first occurrence is..but not the second..it could be 13 characters ahead or 14 or 15 depending on the sms received...

Sory PaulS you didnt get it..

I absolutely DO get it. You are the one that doesn't.

Lets take a really simple example. Suppose that you have a string - "I like pineapple". You use indexOf() to find the first i, in position 3. You use indexOf() again, with 4 as the starting position, and find the next i, in position 5. Now, you KNOW that the second i comes 5 characters after the first i, so there are 4 characters between the is.

That the character you are looking for is a double quote, instead of an i, is completely irrelevant,

fernqn:
i know where the first occurrence is..but not the second..it could be 13 characters ahead or 14 or 15 depending on the sms received...

You do NOT need to tell indexOf() where the next character is. You tell it what to find and where to start. It is obviously smarter than you.

Just try it.

Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".
Use 'indexOf()' again to find the second occurrence of ".

I don't know how to say it any more clearly. What part of that don't you get?

thanks pauls for your example, the difference between that and what i try to xplain, i s that you know your string "I like pineapple"..that could be my number, the problem is that i don't know my string, i mean, i don't know the phone number that sends the sms, is impossible to know if it's goning to be about 13 characters o 14..

how can i do math to create the code?i use 4 or 5 to find the i or the " ?

Do you know there will be a " and another " ?

no men no idea what you're talkin' about..

What character is immediately before your number and immediately after it!?

this is the complete message sohwed in the monitor:

+CMT: "+112233445566","","19/02/08,15:54:59-12"

"What character is immediately before your number and immediately after it!?"

"+112233445566" --> immediately before " and immediately after it " ...

not sure if thats what you tried to tell me...

Yeah.
So, if you can use indexOf() to find the position of the first ", why can't you use it to find the position of the second " ?

If you know the position of the first, say position 9 then you know the position of the + has got to be 10, right?

If you know the position of the second, you know the the position of the last digit is one less than that, right?

Since you know the positions, you can subtract them to get the difference, which is the length, right?

Since you know the position of the starting character and the length you can use substring() to get you number, right?