Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping Characters 1

Status
Not open for further replies.

BAWC01

Technical User
Nov 23, 2005
79
CH
Hi

I have somne text

Code:
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].loc_port    20200
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].connectname smp/smp@ba_asmpma
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].thread_no   6

The problem I have is the following changes is length

Code:
jobs_worker: loc_para[6].thread_no   6
jobs_worker: loc_para[16].thread_no   16
jobs_worker: loc_para[104].thread_no   104

I can read in the text no problem, but how can I strip the [] from a string

I can read the text up until the [
Then read in say the next 3 characters e.g. 6]. 16]

But how can I then trim off what I don't need e.g. ].

Thanks

Phil
 
I think you could use the replace function

[tt]replace(replace(mytext, "]", ""), "[", "")[/tt]

Or use the InStr function to retrieve the position of the character within the string, and use that in your string manipulation functions.

Roy-Vidar
 
Roy

Thanks for that pointer

Having thought about it, is there away of just extracting the characters from between []

e.g.

Code:
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].loc_port    20200
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].connectname smp/smp@ba_asmpma
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].thread_no   6
15.01.06 07:49:39 102374 jobs_worker: loc_para[6].accSocket   0x000003d

I just want the 6

Thanks

Phil
 
Sure, let's say one line of text is in the string variable strText

[tt]dim intStart as integer
intStart = InStr(strText, "[") + 1
intStop = InStr(strText, "]")
msgbox mid$(strText, intStart, intStop - intStart)[/tt]

As I said, just playing a little with the InStr function.

Roy-Vidar
 
Further to my post and thank you Roy for your help.

I have the following strings

Code:
16.11.05 07:22:54 SMP _CAGE_DEPART: 8553 'CBB17B1F1' -> 'STORAGE'

What I would like to do is take each part in the case above

8553 CBB17B1F1 STORAGE

Which I can do but I end up with the quote around the text e.g. 'CBB17B1F1' and 'STORAGE'

How can I just read in the data I need

Thanks

Phil
 
[tt]yourVar = Replace(yourVar, "'", "")[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top