value between 10th > and < (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


lu lu -> value between 10th > and < (10/11/2006 20:48:43)

hi, i have a long string that i need to parse, i'm trying to get the value between the characters of > and <, but starting on the 10th >. so lets say the string is like,

<asdf><asdf><ddd><asdee><asdf><asdf><ddd><asdee><asdf><asdf>getThisValue<ddd><asdee>

getThisValue is after the 10th ">"

how can getThisValue ber gotten?

Thanks




rdouglass -> RE: value between 10th > and < (10/11/2006 21:30:36)

How 'bout this?

<%
DIM myString, myArray, myNewVal
myString = "<asdf><asdf><ddd><asdee><asdf><asdf><ddd><asdee><asdf><asdf>getThisValue<ddd><asdee>"
myArray = split(myString,">")
myNewVal = left(myArray(10),instr(myArray(10),"<")-1)
response.write(myNewVal)
%>




lu lu -> RE: value between 10th > and < (10/11/2006 22:07:33)

very groovey.[;)] Do you fathom that it can be optimized with regular expression?




lu lu -> RE: value between 10th > and < (10/11/2006 22:20:41)

Ok i'm trying to take this one step further by parsing the value in the string after > by these character positions of > in the string:

17,19,21,23,25,27,29,31 //8 numbers odd
38,40, and even until 74 // 19 evens
77,79,81 // 3 numbers odd // 30 numbers in total

DIM myString, myArray, myNewVal, x

myString = "<asdf><asdf><ddd>...<asdee><asdf><asdf><ddd><asdee><asdf><asdf>getThisValue<ddd><asdee>...." 

Dim CharArray(30)

CharArray(0) = 17
CharArray(1) = 19
CharArray(2) = 21
...
CharArray(30) = 81 

For x = LBound(CharArray()) To UBound(CharArray())

myArray = split(myString,">") 
myNewVal = left(myArray(CharArray(x)),instr(myArray(CharArray(x)),"<")-1) 
response.write(myNewVal) 

Next


the error i get is Subscript out of range




rdouglass -> RE: value between 10th > and < (10/12/2006 9:31:12)

quote:

For x = LBound(CharArray()) To UBound(CharArray())

myArray = split(myString,">")
myNewVal = left(myArray(CharArray(x)),instr(myArray(CharArray(x)),"<")-1)
response.write(myNewVal)

Next


I'm not entirely sure what your end goal is but I think you have your loops backwards or something. When you're doing this:

instr(myArray(CharArray(x)),"<")

you are getting 0 for a result. And so when you subtract 1 from it and use it in a LEFT statement like this:

left(myArray(CharArray(x)),instr(myArray(CharArray(x)),"<")-1)

, LEFT has no clue how to do -1 so it chokes.

Are you trying to use those numbers on that stuff after the 10th >? If so, put my original code outside all that other stuff. Don't you want to work with just that and not all the other stuff? Well then my code will give you just that. Put it in a variable and use that variable for your next stuff.

Or maybe I'm waaaaay off. But I thnk you want something different. Maybe you can explain more what you're trying to do with the next step.




lu lu -> RE: value between 10th > and < (10/12/2006 20:01:33)

Ok, i'll try to put it simply, sry for the confusion. This is a new example but the same idea applies. let say i have a string that looks like this, everything between the quotes:

"./ ../ .bash file.xml file_name_here.xml pagefile_here.xml"

i would like to parse the above string and set each xml file name to a variable. The xml file name have no fixed length and no fixed naming convention.






BeTheBall -> RE: value between 10th > and < (10/12/2006 20:19:18)

Can you use Split and put the file names into an array? Looks doable. Using the above example:

myArray = Split("./ ../ .bash file.xml file_name_here.xml pagefile_here.xml"," ")

You then access the values of the array using myArray(0), myArray(1), etc.





lu lu -> RE: value between 10th > and < (10/12/2006 20:23:34)

Thanks Duane,

what about a situation where i don't know the number of xml file names that would be in the string, one time i may have 1 another time i may have 10?

Thanks




BeTheBall -> RE: value between 10th > and < (10/12/2006 20:28:37)

Knowing the number of files isn't a big deal because you can use ubound to get the number of items in the array. However, if the string is completely random, you may run into trouble. Is there anything at all that is uniform about the strings?




lu lu -> RE: value between 10th > and < (10/12/2006 20:45:02)

Strangly as this sounds but i have many senerios that require pasring like this in the same application,

in one instance this is the exact string i'm working with:

"./ ../ .bash_history 100015_200610111421_4001721_S.XML 100015_200610111442_4001721_M.XML 100015_200610111442_4001721_C.XML "

in the case of this type of string, this is alway at the begining: "./ ../ .bash_history " and the xml files always have 3 underscores in them and are always: something_something_something_oneCharacter(either a C,M,or S).xml

Does that help?

So it would start by splitting the string at the spaces but i'm lost as to the next step?

myArray = Split("./ ../ .bash file.xml file_name_here.xml pagefile_here.xml"," ")





BeTheBall -> RE: value between 10th > and < (10/12/2006 21:15:29)

OK. It appears there is a space between ../ and bash, right? If so, then you know your xml files are all the items in the array after 0 and 1. You know how many items are in the array by using:

Ubound(myArray)

So, as an example, you can write the file names like this:

for i = 2 to Ubound(myArray)
Response.write(myArray(i)) & "<br>")
next


EDIT - On closer inspection, it looks like the first 3 items can be tossed, so change:

for i = 2

to

for i = 3




lu lu -> RE: value between 10th > and < (10/12/2006 21:27:00)

Thanks Duane,

I understand UBound and LBound for arrays, what i can't figure out (and this may seem simple) is how to set each value in the array after 3 to a different variable name, maybe something like a1, a2, a3

Thanks




Spooky -> RE: value between 10th > and < (10/12/2006 21:29:06)

Why set it to a variable? you can always use myArray(i)




BeTheBall -> RE: value between 10th > and < (10/12/2006 21:43:41)

quote:

ORIGINAL: Spooky

Why set it to a variable? you can always use myArray(i)


My thoughts exactly.




lu lu -> RE: value between 10th > and < (10/12/2006 21:44:35)

because i want to test to see if the variable had a value, wheni test like this:

x = Trim(Sftp.ListItem)

response.write x ' gives: ./ ../ .bash_history 100015_200610111421_4001721_S.XML 100015_200610111442_4001721_M.XML 100015_200610111442_4001721_C.XML

myArray = Split(x," ")

response.write "x: " & Ubound(myArray) ' gives X: 0 so i don't have an array

for i = 3 to Ubound(myArray)
....

or if i do this:

Response.write myArray(5)
i get error:
Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 5]'

.................

and this: Response.write myArray(i) & "<br>"

give no results

Any thought on this?

I also tried replacing things in the string like . for | and space for ~ so as to split it at the ~ and still no luck?




BeTheBall -> RE: value between 10th > and < (10/12/2006 22:02:37)

Not sure what to tell you. I placed this on a page:

<% x = Trim("./ ../ .bash_history 100015_200610111421_4001721_S.XML 100015_200610111442_4001721_M.XML 100015_200610111442_4001721_C.XML ")
myArray = Split(x," ")
response.write "x: " & Ubound(myArray)
%>


The output is x: 5




lu lu -> RE: value between 10th > and < (10/12/2006 22:20:51)

if i try it in another asp page the code runs fine, but in the page i need it, it don't work?




lu lu -> RE: value between 10th > and < (10/12/2006 22:31:55)

Is it possible that since i created x string value via set Sftp = Server.CreateObject("wodSFTPCom.1")

that the value of the string is not actually a string that can be accessed par say?




BeTheBall -> RE: value between 10th > and < (10/12/2006 23:26:20)

Perhaps a peek at the full code will give us a better idea as to what is going on.




lu lu -> RE: value between 10th > and < (10/12/2006 23:34:13)

ok, well here it is:

<%

dim myArray
dim Sftp, item
dim s,rx,cm,t,x,i

set Sftp = Server.CreateObject("WeOnlyDo.wodSFTPCom.1") ' registerd the dll in system32 folder WindowServer 2003
Sftp.LicenseKey = "xxxxxxxx"
Sftp.Timeout = 60
Sftp.Login = "xxxx"
Sftp.Password = "xxxxxxxxxxxxxxxx"
Sftp.HostName = "ftp.xxxxxx.com"
Sftp.Blocking = 1
Sftp.Connect


Sftp.ListNames "/ftp/www/ON/" 'parsing file names from remote Unix server

x = Trim(Sftp.ListItem) ' get file names and set as a string to x NOTE: trim doesn't work

Sftp.Disconnect
Response.Flush
set Sftp = Nothing

response.write x ' gives the correct value when set to a variable


myArray = Split(x," ")

response.write "X: " & Ubound(myArray) ' yields X: 0
response.write myArray(4) ' yields subscript out of range obviously array function does not work with x value..?

for i = 4 to Ubound(myArray)
Response.write myArray(i) & "<br>"
next


%>




Spooky -> RE: value between 10th > and < (10/13/2006 2:30:12)

response.write "X: " & Ubound(myArray) ' yields X: 0 
response.write myArray(0)
Response.end




lu lu -> RE: value between 10th > and < (10/13/2006 3:30:26)

ok i found out that the value i set to x is a string but one that is not available as a variable. So i can parse the string like Left(x,33) but actually cannot manipulate the string due to SSH and SFTP security. so now i'm looking for a way to parse the string for all characters after the begining part of: " ../ .bash_history "

another words this would have been the replace method:
replace(x,"./ ../ .bash_history ","")

so how can i parse a string of unknow length for its characters minus the begining part of ./ ../ .bash_history

Thanks




Spooky -> RE: value between 10th > and < (10/13/2006 3:57:38)

quote:

x is a string but one that is not available as a variable


Or do you mean one that cant be split? you are trying to split on a space. Are you sure its actually a space character?




lu lu -> RE: value between 10th > and < (10/13/2006 4:06:12)

how would i know? or better yet how can i tell? and what else could it be?




lu lu -> RE: value between 10th > and < (10/13/2006 4:35:46)

well Spooky you go me thinking...

URLEncode=x






For i = Len(URLEncode) To 1 Step -1
acode = Asc(Mid(URLEncode, i, 1))
Select Case acode
Case 48,49,50,51,52,53,54,55,56,57, 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,86,83.,84,85,87,88,89,90, 97,98,99,100,102,103,1047,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122
' don't touch alphanumeric chars
Case 32
' replace space with "+"
Mid(URLEncode, i, 1) = "+"
Case Else
' replace punctuation chars with "%hex"
URLEncode = Left(URLEncode, i - 1) & "%" & Hex(acode) & Mid _
(URLEncode, i + 1)
End Select
Next

response.write URLEncode
' above yields:
100015%5F200610111421%5F4001721%5FS%2EXML%D%A100015%5F200610111442%5F4001721%5FM%2EXML%D%A100015%5F200610111442%5F4001721%5FC%2EXML%D%A

so the spaces were actually: %D%A

interesting....




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
9.399414E-02