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

Parsing strings

Status
Not open for further replies.

lesuk

Technical User
Dec 17, 2001
2
GB
Hi all,

Im in need of some support in writing a piece of VB Scrip for my website.

Im pulling data from a Access data base and want the data to be in the correct format, as in the capitals in the correct places etc, "House not house"

Ive got the first bit going ok in that the fields from tha data base with only one word entrys can be displayed like this one

<% myVar_location = (RS_member_detail_page.Fields.Item(&quot;location&quot;).Value)Response.Write(uCase(left(myvar_location,1))) & (right(myvar_location, Len(myvar_location)-1))
%>

Now being a newbie to VBS this took me a while to figure out..........So If one of the recordsets being pulled has a field in which there is a sentence or a few words

Can anyone advise me on how to count the words and number of charactures used.

Im not sure how to parse spaces? If there is a sentance is it just recognised as 1 string..

Many thanks in advance

Les.


 
In VB and VBA you have the StrConv() function, which can convert a text string to &quot;proper case&quot; as you describe, in one step.

Sadly, VBScript doesn't have this function for some odd reason.

If you are SURE your strings have only words separated by spaces (no other punctuation to throw you off) you can use the Split() and Join() functions to accomplish this.

These functions will tear a string down [Split()] or build a string up [Join()] using a specified delimiter. I think the default is a space as a matter of fact.

Split() returns an array of strings, then you just process each array element as you described for your &quot;one word&quot; strings. After this you can Join() the array back up into a string.

See the online help for VBScript for details and examples.

Don't have the help (scary thought)? Go to and browse a little - you'll find it!
 
Thanks very much.
I will give that a try,
I wanted to know how to take control of text entered or displayed.
I had a comments field in mind, and wanted to control the amount of chars/words?? entered, then eventually filter out unwanted words(swear words)
I will mull on it...I have VBS/VBA in a nutshell comming from santa so I'm more fevered up than the kids.......
Thanks again
Les.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top