Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 1st, 2004, 10:24 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default string splitting

ive a text string like this ..

John Markus K Philip

i need to split it into 3 parts and take it to 3 variables like:
var1: John
var2: Markus
var3: K Philip

if only i name is there it shud only be using var1 and the other 3 vars r left blank .. howto do this ?

Reply With Quote
  #2 (permalink)  
Old February 1st, 2004, 09:41 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Dim arrFullName()
'split the full name into the array
arrFullName = split(strName," ")

'check how many elements are in the array
select case ubound(arrFullName)
 case 1
  'Code to handle one name entered
  var1 = arrFullName(0)
 case 2
  'code to handle two names entered
  var1 = arrFullName(0)
  var2 = arrFullName(1)
 case 3
  'code to handle three names entered
  var1 = arrFullName(0)
  var2 = arrFullName(1)
  var3 = arrFullName(2)
 case 4
  'code to handle Four names entered
  var1 = arrFullName(0)
  var2 = arrFullName(1)
  var3 = arrFullName(2) & " " & arrFullName(3)
end select

BUT:
This is a very about face way of dealing with a name, you should try to get entered in the fields for first name, second, etc and then join them when you need a full name. With the huge variety of name formats out there I'd hate to have to rely on this method.

EG
"John Markus K Philip" would be
John
Markus
K Philip

BUT
"John K Philip" would be
John
K
Philip

Different result just because the didn't wish to provide (or didn't have) a middle name.


======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Reply With Quote
  #3 (permalink)  
Old February 2nd, 2004, 02:06 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i get this error ..

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
/clinicasp/DBConvert.asp, line 49

the input thru strName is string only ...

Reply With Quote
  #4 (permalink)  
Old February 2nd, 2004, 02:20 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sorry,
My mistake.

Dim arrFullName
NOT
Dim arrFullName()

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Reply With Quote
  #5 (permalink)  
Old February 2nd, 2004, 02:25 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sorry, there are further mistakes, I really didn't think when doing this one.

The case statement should be from a base of 0 (zero)

so
 case 1
 case 2
  ...etc

should be case 0, case 1, ...etc.

Below is working code to illustrate clearly
Code:
<% @language = "vbscript" %>
<html>
<head>
    <title>Untitled</title>
</head>
<body>
<%
Dim arrFullName
dim strName
'split the full name into the array
strName = "John Markus K Philip"
arrFullName = split(strName," ")

'check how many elements are in the array
select case ubound(arrFullName)
 case 0
  'Code to handle one name entered
  var1 = arrFullName(0)
 case 1
  'code to handle two names entered
  var1 = arrFullName(0)
  var2 = arrFullName(1)
 case 2
  'code to handle three names entered
  var1 = arrFullName(0)
  var2 = arrFullName(1)
  var3 = arrFullName(2)
 case 3
  'code to handle Four names entered
  var1 = arrFullName(0)
  var2 = arrFullName(1)
  var3 = arrFullName(2) & " " & arrFullName(3)
end select

response.write("<BR>Var1 = " & var1)
response.write("<BR>Var1 = " & var2)
response.write("<BR>Var1 = " & var3)
%>
</body>
</html>
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Reply With Quote
  #6 (permalink)  
Old February 2nd, 2004, 05:59 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanx it works perfectly now ..

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting a text string ghall202 Access 4 February 14th, 2008 05:45 PM
evc++: splitting string into array using strtok bluebeta Visual C++ 2 May 3rd, 2006 01:49 AM
Splitting of string lily611 SQL Server 2000 3 March 19th, 2005 08:17 AM
Splitting Strings ryanpatrick Classic ASP Basics 2 March 9th, 2004 02:42 PM
splitting this string menesesg Classic ASP Basics 1 September 10th, 2003 12:40 AM



All times are GMT -4. The time now is 02:28 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.