extracting text out from a string.

najmul
09-10-2003, 12:11 AM
Hi guys,
been in the site for quite a while, and i'm wondering if you guys can help me with an algorithm question..

my boss has given me this to figure out to be used in the an application i'm developing.

let's say i'm given a scenario like this.

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"


'im supposed to figure out an algorithm such to extract the two text.
' the strText2 has no limit in alphabets..
strText2 = "CUS"
strText3 = "please come to meeting room 8"

'so
strText1 = "*HELPDESK* please come to meeting room 8"
'should give
strText2 = "HELPDESK"
strText3 = "please come to meeting room 8"

the algorithm is supposed to find a way to seperate the string. The (*) is supposed to identify for strText2 .

anybody can help?
any help given is greatly appreciated.

i tried using the Mid function but the value for strText2 can only be constant.

thanks,
naj

rajeeshun
09-10-2003, 12:21 AM
Hi guys,
been in the site for quite a while, and i'm wondering if you guys can help me with an algorithm question..

my boss has given me this to figure out to be used in the an application i'm developing.

let's say i'm given a scenario like this.

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"


'im supposed to figure out an algorithm such to extract the two text.
' the strText2 has no limit in alphabets..
strText2 = "CUS"
strText3 = "please come to meeting room 8"

'so
strText1 = "*HELPDESK* please come to meeting room 8"
'should give
strText2 = "HELPDESK"
strText3 = "please come to meeting room 8"

the algorithm is supposed to find a way to seperate the string. The (*) is supposed to identify for strText2 .

anybody can help?
any help given is greatly appreciated.

i tried using the Mid function but the value for strText2 can only be constant.

thanks,
naj


Hi,
Use Replace() function.
knowing about instr() function also wud be helpful for you

najmul
09-10-2003, 12:28 AM
Hi,
thanks for the prompt reply..

but i'm still unsure about extracting the values between the asterisks and after it.

i tried doing this way, but couldn't get it...

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"

'strText2= Instr(4, strText1 , "*", 1)

'strText3= Replace("strText1 ", "*", " ")

i'm quite unclear on figuring out the way to extract it.

thanks,.

rajeeshun
09-10-2003, 12:44 AM
Hi,
thanks for the prompt reply..

but i'm still unsure about extracting the values between the asterisks and after it.

i tried doing this way, but couldn't get it...

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"

'strText2= Instr(4, strText1 , "*", 1)

'strText3= Replace("strText1 ", "*", " ")

i'm quite unclear on figuring out the way to extract it.

thanks,.



Hello,
see... if you want to remove the "*" then just use replace function only

strtext3=replace(strtext1,"*","")

Dremandred
09-10-2003, 12:44 AM
Try checking for the * by using 'Asc(42)' (the assci for *)
then reading one character at a time into strText2 until your
sChar = Asc(42) for the second time

It's more of an idea than an answer, it will need some playing around I think. But it should give you a good idea
Something like:
if sChar = Asc(42) then
sChar = ""
Do until sChar = Asc(42)
sChar = Input(strText?, 1)
strText? = strText? & sChar
sChar = ""
Loop
strText = Answer

najmul
09-10-2003, 12:58 AM
Hi
thanks for the quick response.
i kinndda found a solution..
instead of using * i used ( and )
but it needs further help..

Dim strT, strT12, strT13
strT = "(Helpdesk) come to the office"

strT12 = Mid(strT, InStr(strT, "(") + 1, InStr(strT, ")") - InStr(strT, "(") - 1)

'i figured out a away to extract the "helpdesk", but how do i get the rest of the "come to the office" part?

i tried using this.
strT13 = Mid(strT, InStr(strT, ")"), ????)

how do i get the last alphabet of the sentence??

thanks,

najmul
09-10-2003, 01:02 AM
Hello,
see... if you want to remove the "*" then just use replace function only

strtext3=replace(strtext1,"*","")

hi

i used your method and it works!!

but i can't get the rest of the sentence out..

thanks,
naj

jcheah
09-10-2003, 01:03 AM
You can use the "*".......

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"

strText2 = Mid(strText1, 2, InStr(strText1, "* ") - 2)
strText3 = Right(strText1, Len(strText1) - (InStr(strText1, "* ") + 1))


jc

najmul
09-10-2003, 01:07 AM
You can use the "*".......

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"

strText2 = Mid(strText1, 2, InStr(strText1, "* ") - 2)
strText3 = Right(strText1, Len(strText1) - (InStr(strText1, "* ") + 1))


jc

BINGO!!!

thanks jcheah!! got the answer..
thanks to Dremandred and rajeeshun for help me out!!

rajeeshun
09-10-2003, 01:12 AM
You can use the "*".......

Dim strText1, strText2, strText3

strText1 = "*CUS* please come to meeting room 8"

strText2 = Mid(strText1, 2, InStr(strText1, "* ") - 2)
strText3 = Right(strText1, Len(strText1) - (InStr(strText1, "* ") + 1))


jc

BINGO!!!

thanks jcheah!! got the answer..
thanks to Dremandred and rajeeshun for help me out!!


..Appreciated !!
One small concern
Whenever you adding your vb code use Vb tags. then it will give you VB formated code

dim strT as string

najmul
09-10-2003, 02:05 AM
..Appreciated !!
One small concern
Whenever you adding your vb code use Vb tags. then it will give you VB formated code

dim strT as string



thanks for tip!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum