Extracting a variable from a string
espen.sandorf
Posts: 29
Hi all.
I'm Trying to extract a variable from a string to define a CallId. I'm Working With a Tandberg C60.
The string i'm trying to get is sent to me in a string with much information. All i want to do is to extract The word: Call followed by up to 5 digits. Then remove Call and make the digits that can be everthing from 1 to 65000 (something) into an integer.
The string i send to the codec is this:
The nCallId is the integer representing the variable.
My problem is that when say i want 5 digits i only get one , i also receive alot of crap i dont want, and the the codec doesn't recognise the CallID.
And when i specify that i only want one digit, i'm out when the counter reaches 10.
Thanks for any help that leads me in the right direction. Examples are wery much appiciated.
I'm Trying to extract a variable from a string to define a CallId. I'm Working With a Tandberg C60.
The string i'm trying to get is sent to me in a string with much information. All i want to do is to extract The word: Call followed by up to 5 digits. Then remove Call and make the digits that can be everthing from 1 to 65000 (something) into an integer.
The string i send to the codec is this:
SEND_STRING dvTandberg, "'xCommand DTMFSend CallId:',nCallId,'DTMFString:',DATA.TEXT,$0D"
The nCallId is the integer representing the variable.
My problem is that when say i want 5 digits i only get one , i also receive alot of crap i dont want, and the the codec doesn't recognise the CallID.
And when i specify that i only want one digit, i'm out when the counter reaches 10.
Thanks for any help that leads me in the right direction. Examples are wery much appiciated.
0
Comments
what kind of variable is nCallId ? can you post the declaration of it?
take out the itoa
nCallId = ITOA(ATOI(sIncMsg));
make it nCallId = ATOI(sIncMsg)
I Belive i tried that aswell. I'm not sure why, but when i do it like this the nCallId is 3 when its really 34.
Like this.
Call 34 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA
In theory the string can be:
Call 4006 status=Disconnected, type=NA, protocol=NA, direction=NA, logTag=NA
Well, that string is too long to fit in your 50 char buffer. Perhaps make the buffer size large enough to hold it and see.
If that is your actual string you could use atoi() on the whole string and it will ignore all non numerical parts of the string and just give you the digits. That would require that no other numbers show up in your data though. Otherwise I think I would use
remove_string(sIncMsg,'Call ',1)
atoi(remove_string(sIncMsg,' ',1))
Paul
This is what the actual string looks like
Now based on this:
I would try this: Also in your code example: You're looking for a string with *s and you example above doesn't show that which is why using the send_string 0 to show what you actually get is very helpful. Also when I use find_string and then use remove_string I always make the strings identical. You have spaces called for in your find_string but not your remove string and it is always possible that there may be a "Call" before a "Call " followed by spaces in the returned string and that will really screw with you head until you realize what's going on.
I dont have access to a c-series codec right now so i'll have to wait a few days before i can post the acctual string.
I believe the *s is the correct beginning of the string, is just me trying out different stuff.
Lets say the String looks like this:
All the NA are variables and will change from call to call, it can be both letters and numbers. I want to get the string, then dispose *s Call and everything from status to the end of the string. Then i will be left with the call-id regardless of how many digits it made of.
Does this sound correct?
When i send the string to 0, where do i read that string?
Are they always in the same order?
Are they always seperated by commas as in your example.
Do the send_string 0 and let's see what and how strings come in.
String From [5001:3:1]-[*s Call 8 Status: Connected$0D$0A*s Call 8 Direction: Outgoing$0D$0A*s C]
String From [5001:3:1]-[all 8 Protocol: "h323"$0D$0A*s Call 8 CallType: Video$0D$0A*s Call 8 Rem]
String From [5001:3:1]-[oteNumber: "21625200"$0D$0A*s Call 8 CallbackNumber: "h323:21625200"]
String From [5001:3:1]-[$0D$0A*s Call 8 DisplayName: "HCB-CVCE003"$0D$0A*s Call 8 TransmitCallRa]
String From [5001:3:1]-[te: 768$0D$0A*s Call 8 ReceiveCallRate: 768$0D$0A*s Call 8 Encryption Ty]
String From [5001:3:1]-[pe: "None"$0D$0A*s Call 8 PlacedOnHold: False$0D$0A*s Call 8 Duration: 5]
String From [5001:3:1]-[85$0D$0A** end$0D$0A$0D$0AOK$0D$0A]
There were errors in the previous example so that shouldn't have worked anyway. Based on what the send_string 0's returned this example should (if it actually compiles) be pretty close to what you want. Hope this helps.
I've been trying to code in UNIX (shell) and Perl this past week and I've found that life would be alot easier if there were decent examples available (googling) instead of trying to read a bunch of cryptic manuals that just make my eyes glaze over. If I can see how it's done I can usually understand but trying to figure $**** out from scratch just sucks.