|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
querystring and isarray help
This is really weird, No matter what, i get true for the is array function on a querystring variable, anyone have ideas?
Let's say I pass in "george michaels" or "george" both return true on the is array, yet the A(1) will error if you try and access it on a "george" split on space. Code:
name = Cstr(mid(request.querystring("name"),2,(len(request.querystring("name"))-2)))
response.write name & "<br>"
Arr=split(name," ")
response.write Arr(0) & "<br>"
'response.write Arr(1) & "<br>"
response.write IsArray(Arr)
if isarray(Arr) then
response.write "muliname<br>"
else
Do something
End if
Does anyone have any clue or any advice at all? |
|
#2
|
|||
|
|||
|
alright, now i'm really freaked out, this is hardcoded in:
Code:
name = "george michaels" Arr=split(name," ") response.write IsArray(Arr) name = "george" Arr=split(name," ") response.write IsArray(Arr) Both output true.... |
|
#3
|
|||
|
|||
|
Well of course it outputs *TRUE*
You know why ??? Because if you read the docs for SPLIT() it says: Returns a zero-based, one-dimensional array containing a specified number of substrings. So : name = "george michaels" Arr = split(name," ") <---split() will return an array so Arr is an array response.write IsArray(Arr) <--Will return TRUE because Arr is in fact an array That's why! Hope this helps! Sincerely Vlince |
|
#4
|
|||
|
|||
|
how would one find out if the split worked then?
I'm passing in a name whether it be first, last, or both, and i need to check to see if the split worked, I guess i'll have to use instr(name, " ")... stupid split... |
|
#5
|
|||
|
|||
|
I'm sorry, I don't get it :-(
What do you mean by: ---BEGIN QUOTE how would one find out if the split worked then? ---END QUOTE You're the programmer so why are you using the Split() function in the first place? If your are then you must have a good reason for no? Let me ask you this: Will you *always* have the First Name and Last Name OR can it sometimes be *ONLY* the First Name OR *ONLY* the Last Name OR BOTH One thing you can try is: <% Dim Arr Arr = Split(Request.Form("Something"))(0) Response.Write Arr OR if you want the second element in the array do: Arr = Split(Request.Form("Something"))(1) Response.Write Arr NOTICE the (0) and (1) part! Hope this helps! Sincerely Vlince %> |
|
#6
|
|||
|
|||
|
Can't say I've ever seen the split function be used the way you're using it, and can't find any documentation on it and it errors on me when i copy your code so i'm not sure what you're getting at.
sorry for being unclear. Yes I am the programmer and am quite aware of why I'm using the split function. Thanks for your help on the IsArray and split, i assumed the split returned a scalar variable if there was no splitting, but it's not as you stated which is why it's always true first, last, or both names are passed in, i don't know which it will be, it's random, sometimes a person knows their first name, sometimes just the last, sometimes they know a little of each, it's a guess as to what they'll know really. I have first and last names in a DB and have to parse the name if they give me "geo mi" then i have to search like '%geo%' in the first name field and '%mi%' in the last name field and return the results. I have it solved by using that instr function i was telling you about. Code:
B = InStr(name," ") It just returns 0, the space just doesn't exist in the string and i continue on my merry way, i'm sure you knew that but that's how i'm using it. regaurds |
|
#7
|
|||
|
|||
|
You are right, using the Split() the way I'm using it isn't documented but it works here copy/paste this example:
<% Dim str str = "The dog is red" Response.Write "-->" & Split(str, " ")(0) & "<--<br>" Response.Write "-->" & Split(str, " ")(1) & "<--<br>" Response.Write "-->" & Split(str, " ")(2) & "<--<br>" Response.Write "-->" & Split(str, " ")(3) & "<--<hr>" %> The end result should display: -->The<-- -->dog<-- -->is<-- -->red<-- Using the Split() the way I'm using it is a shortcut and returns *ONLY* the string I WANT. Notice that IT DOES NOT return an array since I wanted element (0) for example, so it only returned the string placed a element (0) Of course if you have a string such as str = "My cat" and you ask for this: Response.Write "-->" & Split(str, " ")(2) & "<--<hr>" This will not work, in fact I think its going to give you an error message since you dont have an element (2) in that string str Vlince |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > querystring and isarray help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|