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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read string 3

Status
Not open for further replies.

Footbal76

MIS
Sep 6, 2006
21
US
I have this string of text. Within the string there is a space. And then it proceeds with the string.

I would like to parse the string out every 3 characters after the SPACE in its separate string

So example if sparsed out every 3 characters it would look like this

ART 1string
ASC 2string
BIO 3string
HUM 4string
JUR 5string
MPS 6string
ect:

here is the string
RSAP5RSCH8RSDB1RSID1RSIV6RSLG9RSUM1RUWE1 ARTASCBIOHUMJURMPSMUSSBSUSSUVC
 
First, you need to split the big trsing at the space:
arTempStr = split(YourBigStr, " ")

The left of the big string is arTempStr(0) and the right is arTempStr(1)

Now, get the first 3 chars of the string after the space:
3charStr = Left(arTempStr(1),3)
 
Say you have an array AAA of n strings
Code:
strResult = ""
for i = 1 to n
   strResult = strResult + left(AAA(i),3)
next
 
I get this error

An unhandled data type was encountered.

strlngth = Len(retval)
Response.Write(retval)
Str = split(retval, " ")
Response.Write(Str)
 
Str = split(retval, " ")

This is an array of string. You need to specify array index, ie, response.write(Str(0)) or response.write(Str(1))

 
Having a problem. I have this variable that
Response.Write totalcolls gives this line

totalcolls = Mid(colls,i+1,colls_lgth)
Response.Write totalcolls

ARTASCBIOHUMJURMPSMUSSBSUSSUVC this is the line


Now I'm trying to parse this line out every three characters.

Dim strCol2
i = 0
strCol2 = Left(totalcolls,3,colls_lgth)

response.write strCol2

But I'm getting this ERROR.
ERROR
Wrong number of arguments or invalid property assignment: 'Left'
 
What about using the Mid() function?
[tt]
MyString = "ARTASCBIOHUMJURMPSMUSSBSUSSUVC"
SetLength = 3
SetCount = Len(MyString) Mod SetLength
For i = 1 to SetCount
StartPosition = i * SetLength
Response.Write Mid(MyString, StartPosition, SetLength)
Next
[/tt]
 
I get no response from the response.write function

Do u have any other suggestions?
Thanks

SetLength = 3
SetCount = Len(totalcolls) Mod SetLength
For i = 1 to SetCount
StartPosition = i * SetLength
Response.Write Mid(totalcolls, StartPosition, SetLength)
Next
 
OK first I had a logic error:
Counting up the "sets" would be a normal numeric progression but the starting position would be different than just 3 times the set number. So the first code I posted would do this:
1 3
2 6
3 9
4 12
5 15

That is obviously quite wrong. We need this:
1 1
2 4
3 7
4 10
5 13

This could be expressed as [tt](A * 3) - 2 = B[/tt]

So lets try rewriting it and also adding some extra Response.Write lines for debugging:

[tt]
Response.Write "The starting string is: " & totalcolls & "<br>" 'debug
SetLength = 3
SetCount = Len(totalcolls) Mod SetLength
For i = 1 to SetCount
StartPosition = (i * SetLength) - (SetLength - 1)
Response.Write "i = " & i & "<br>" 'debug
Response.Write "StartPosition = " & StartPosition & "<br>" 'debug
Response.Write "The value is: " & Mid(totalcolls, StartPosition, SetLength) & "<br>"
Next
[/tt]
 
Ok I get a response back from the the first response.write

but the other part does not seem to work

here is the output:

any suggestions

The starting string is: ARTASCBIOHUMJURMPSMUSSBSUSSUVC



Also here is most of the code I'm working with.
It might explain why its not working

colls = Mid(retval,12,strlngth)
'response.Write("<bR><br>" & colls & "++")
colls_lgth = Len(colls)

For i = 5 To colls_lgth
chk = Mid(colls,i,1)
If IsNumeric(chk) Then
'Response.Write("<br>" & "trues")
'response.write chk
Else
Exit For
End If
i = i+4
Next

totalcolls = Mid(colls,i+1,colls_lgth)
THE TOP CODE HERE GENERATES THE: ARTASCBIOHUMJURMPSMUSSBSUSSUVC

Response.Write "The starting string is: " & totalcolls & "<br>" 'debug
SetLength = 3
SetCount = Len(totalcolls) Mod SetLength
For i = 1 to SetCount
StartPosition = (i * SetLength) - (SetLength - 1)
Response.Write "i = " & i & "<br>" 'debug
Response.Write "StartPosition = " & StartPosition & "<br>" 'debug
Response.Write "The value is: " & Mid(totalcolls, StartPosition, SetLength) & "<br>"
Next
 
oh I am careless today... I put a mod where I needed a div

The existing line:
[tt]SetCount = Len(totalcolls) [red]Mod[/red] SetLength [/tt]

should instead be:
SetCount = Len(totalcolls) [red]/[/red] SetLength
 
Ok that worked

here is the ouput.
This goes on forever

The starting string is: ARTASCBIOHUMJURMPSMUSSBSUSSUVC i = 1
StartPosition = 1
The value is:
i = 2
StartPosition = 4
The value is:
i = 3
StartPosition = 7
The value is:
i = 4
StartPosition = 10
The value is:
i = 5
StartPosition = 13

Now how would I get the ART out of the string into a separate string

And then ASC
and BIO

I need separate varibale string for each one.

Any help would be appraciated
 
you could put the values into an array:

[tt]
totalcolls = "ARTASCBIOHUMJURMPSMUSSBSUSSUVC"
SetLength = 3
SetCount = Len(totalcolls) / SetLength
Dim TheArray()
ReDim TheArray(SetCount)
For i = 1 to SetCount
StartPosition = (i * SetLength) - (SetLength - 1)
TheArray(i) = Mid(totalcolls, StartPosition, SetLength)
Next

Response.Write "The item at index 1 is: " & TheArray(1) & "<br>"
Response.Write "The item at index 5 is: " & TheArray(5) & "<br>"
[/tt]
 
For some reason its not picking up the value.
I used your example:

output:
The item at index 1 is:
 
ok that is strange.

I made an ASP that only contains the following:
Code:
<%
totalcolls = "ARTASCBIOHUMJURMPSMUSSBSUSSUVC"
SetLength = 3
SetCount = Len(totalcolls) / SetLength 
Dim TheArray()
ReDim TheArray(SetCount)
For i = 1 to SetCount
  StartPosition = (i * SetLength) - (SetLength - 1)
  TheArray(i) = Mid(totalcolls, StartPosition, SetLength) 
Next

Response.Write "The item at index 1 is: " & TheArray(1) & "<br>"
Response.Write "The item at index 5 is: " & TheArray(5) & "<br>"
%>

And the results of that page are:
The item at index 1 is: ART
The item at index 5 is: JUR
 
well I don't have totalcolls setup like they way you have it. let me test your code separatly and see if I get what you have.
 
That worked separate like u said.
Im trying to test the Array to se if there is any data in there
 
Seems like a bunch of work for this unless I didn't read completely as I do often.

Wouldn't it be much easier to use a regular expression match collection?

something like

Code:
totalcolls  = "ARTASCBIOHUMJURMPSMUSSBSUSSUVC"

Set regex = New RegExp
With regex
.Pattern = "[a-zA-Z]{3}"
.IgnoreCase = False
.Global = True
End With

Set matchCol = regex.Execute(totalcolls)

If matchCol.Count > 0 Then
For Each match in matchCol
	Response.Write match.Value & " " & match.FirstIndex & "<br>"
Next
End If


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
onpnt

That works great. Question how would I put each value into one string.

The output looks like this:
ART
ASC
BIO
HUM
JUR
MPS
MUS
SBS
USS
UVC

So I guess this loops through and prints out every 3 characters with a "<br>" for break

I need to put each one of these ART, ASC, BIO, HUM, JUR, MPS, MUS, SBS, USS, UVC

In its own string or variable for manipulation.

Thanks in Advance
 
Unless you know in advance exactly how many of these 3 letter codes will exist in the input string then you'll really want to use an array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top