STrings MAniPulation in a textbox

xin1117

Newcomer
Joined
Dec 17, 2003
Messages
20
Hi friends oUT there...

i haf a question regarding strings manipulations.....

if i haf a strings of codes in a textbox how do i extract the specific data i want in that textbox? for e.g in that text box i haf
AT+CGMR='18',+CMTI,+88888,+16:04:08,+hihi
i wana to retrieve +8888 into another textbox....

do i use substring to solve the problem....?? :confused: or are there ani other ways i can solve this problem?
can anibody help mi ????

tHAnks in adVANce.......
 
If your string is always build in the same way, try using the split-function using ",+" or just "," as splitter. You will get an Array of Strings. Then you can take the item needed. In your case it would look like that:
Visual Basic:
Dim mystrArray as String() = mystring.Split(",")
mystr = mystrArray(2)
Given your example you should get +88888. (Can't verify it - no VS.net near :( )
Voca
 
hihi

thanks for your reply

btw i m using vb.net =)

u mention about split functions.... do i need functions like instr or substring to do ??

:)
 
Look at the vb-net-code above, it should work like that. Just assign your value to your textbox. You do not need instr(), substr() or something like that!

Voca
 
hihi


cmdCode0:
AT+CMGR=13

+CMGR: "REC UNREAD","+888888",,"03/12/17,16:29:41+32"
take care

as i mention earlier on, this is the actual data that will appear on my textbox when i receive a sms.... how can i extract the +888888 to appear on another textbox????

the method voca mention earlier on i tried but it only appear 16:29

any other suggestion??

thanks =)

:cool:
 
Perhaps you could send your code, so we could fix it. Looks like you simply messed up some indices or the splitting char. Did you use ","? With that you should get at least 5 items in your array.

Voca
 
HMm what do u mean i mess up with the indices and splitting char? if i m not wrong the data in the textbox that my modem receive is default thats y i m uncertain if i can use "," as what u had mention earlier on because there are a mixture of : and " in my string of data as well. sorry kinda new to string manipulation can you kindly explain the 5 items in my array that i will get?? thanks alot =)
 
hi,

given the string "AT+CGMR='18',+CMTI,+88888,+16:04:08,+hihi" and using "," as splitting char you should get :

item(0) = AT+CGMR='18'
item(1) = +CMTI
item(2) = +88888
item(3) = +16:04:08
item(4) = +hihi (if hihi contains "," there will be several more items)

The reason I thought that you messed up the indices is that you recieved the time, having index 3 instead of the numeric Value having index 2.
I assume this mixture of symbols you mentioned normaly comes with the hihi-Part of your string? This should not matter, as the first 4 items 0 to 3 always stay the same.
As you want to show this string in a Textbox you can do it like this:
Visual Basic:
Me.MyTextBox.Text = mYString.Split(",")(2)

Voca
 
hiHi

THanks for your reply

HMm i UNderstand the 5 item in the array...but does that means by doing this way cmdCode0: and "REC UNREAD" and the dates will automaticalyl not be included in the array??
 
Every part of your String is put into an item of your Array. That means both REC UNREAD and your Command are in an item.

If you send the whole String I would tell you where to find them. The function Split only splits your String int oseveral pieces. No part of your String will be lost. If something is not included in your string it will not be there

Btw.: Where do you get REC UNREAD and cmd... from? Should they be in your string?

Voca
 
Sorry: lost track of your string if this is your string:
cmdCode0:AT+CMGR=13,+CMGR: "REC UNREAD","+888888",,"03/12/17,16:29:41+32"


the items mystring.split (",") will create are:
item(0) = cmdCode0:AT+CMGR=13
item(1) = +CMGR: "REC UNREAD"
item(2) = +888888
item(3) = "" -> because there is no text
item(4) = 03/12/17
item(5) = 16:29:41+32


Voca
 
hihi

when i send an sms from the hp to the program... it will automatically display


cmdCode0:
AT+CMGR=13

+CMGR: "REC UNREAD","+888888",,"03/12/17,16:29:41+32"
take care

cmdCode0: is wad i had added.. it can be deleted away...
as for REC UNREAD is the SIm CARd status...... therefore there is no way i can remove this sentence....

and hmm one last question... if i use "," as the split delimter, it will affect the the ":" in +CMGR: isist?
 
Normaly it should not affect anything. Split only should split your string into a certain number of parts but not affect any chars of your string. There must be some other method/function affecting your string.

Must be some new feature I did not get till now ;) :p

Voca
 
As your string seems to be changed while executing the programm (affecting the ":") there must be some other code (within a Sub or Function), working with your string.

Voca
 
HiHi

cmdCode0:AT+CMGR=13+CMGR: "REC UNREAD","+888888",,"03/12/17,16:29:41+32"
take care


the string here cmdCode0:AT+CMGR = n +CMGR:"REC UNREAD",

is fixed where n will +1 each time i execute the application. in this

way will it still affect??
 
It only affects your string, splitting is not affected. If you increment n yourself I would use n.tostring.

Voca
 
HiHi

i observe the response again n realise that b4 it reaches this response, cmdCode0:AT+CMGR=n +CMGR: "REC UNREAD","+888888",,"03/12/17,16:29:41+32"
take care

it appear cmdCode0: SM,n

where n will +1 each time i execute the application.

the codes that i use to arrive n are

If InStr(myString, "SM") Then
indexnum = fromModem.Substring(fromModem.Length - 2)

AxMSComm1.Output = "AT+CMGR=" & indexnum & vbCr

could this string affect me from retrieving the item i want??
 
AS long as n is separated by a "," you get one more element than those time when it is interned into your string.

Voca
 
Back
Top