Simple Snippet Question (stripping variable value)

# Thread: Simple Snippet Question (stripping variable value)

1. Junior Member
Join Date
Dec 1969
Posts
26

## Simple Snippet Question (stripping variable value)

The following snippet takes the variable PageName and replaces the underscoores with spaces. An example of the value of PageName is picture_gallery.<BR><BR>&#060;% <BR>PageName = Trim(PageName)<BR>arrWords = Split(PageName, "_", "-1", 1) <BR><BR>For Each strOneWord in arrWords<BR>Response.Write(strOneWord) & " "<BR>Next<BR><BR>%&#062;<BR><BR>How do you make it so that it takes the value of PageName and capitalizes the first letter of each word so the value picture_gallery would become Picture Gallery after the rendering??<BR><BR>Any help is appreciated. Pls send me an email if possible: andyt1286@yahoo.com<BR><BR>Andy

2. Senior Member
Join Date
Dec 1969
Posts
731

## RE: Simple Snippet Question (stripping variable va

after u replace them with the space, split them with the space character. now u have got an array of words "picture" and "gallery". Now loop thru the array and say ucase(left(array(i),1)). So the first character is capitalized. that solves ur problem. Then use the join or other methods to concatinate the strings.

3. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Simple Snippet Question (stripping variable va

Either that, or just do something like:<BR><BR>For i=0 to in UBound(arrWords)<BR> strWord = arrWords(i)<BR> strWord = UCase(Left(strWord, 1) & Right(strWord, Len(strWord)-1)<BR> arrWords(i) = strWord<BR>Next<BR><BR>And then just join the arrWords array.<BR><BR>Craig.

4. Junior Member
Join Date
Dec 1969
Posts
26

## Okay...One more...

Okay when I try putting the spacer code in with the capitalization code I had this:<BR><BR>&#060;% <BR> PageName = Trim(PageName)<BR> arrWords = Split(PageName, "_", "-1", 1) <BR> <BR> For i=0 to in UBound(arrWords) <BR> strWord = arrWords(i) <BR> strWord = UCase(Left(strWord, 1) & Right(strWord, Len(strWord)-1) <BR> arrWords(i) = strWord <BR> Response.Write(strWord) & " "<BR> Next<BR>%&#062;<BR><BR>What did I do wrong there? I was trying to combine your code:<BR><BR>For i=0 to in UBound(arrWords)<BR>strWord = arrWords(i)<BR>strWord = UCase(Left(strWord, 1) & Right(strWord, Len(strWord)-1)<BR>arrWords(i) = strWord<BR>Next<BR><BR>with mine:<BR><BR>&#060;% <BR>PageName = Trim(PageName) <BR>arrWords = Split(PageName, "_", "-1", 1) <BR><BR>For Each strOneWord in arrWords <BR>Response.Write(strOneWord) & " " <BR>Next <BR>%&#062; <BR><BR>Thanks.<BR>Andy<BR>andyt1286@yahoo.com

5. Senior Member
Join Date
Dec 1969
Posts
484

## script

hey, keep in my code dump this script which I found somewhere and seems to do the job.<BR><BR>&#060;script language="JavaScript1.2"&#062;&#060;!--<BR>function toUpper() {<BR>var pattern = /(w)(w*)/; // a letter, and then one, none or more letters<BR><BR>var a = document.form1.text1.value.split(/s+/g); // split the sentence into an array of words<BR><BR>for (i = 0 ; i &#060; a.length ; i ++ ) {<BR>var parts = a[i].match(pattern); // just a temp variable to store the fragments in.<BR><BR>var firstLetter = parts[1].toUpperCase();<BR>var restOfWord = parts[2].toLowerCase();<BR><BR>a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on<BR>}<BR><BR>document.form1.text1.value = a.join(&#039; &#039;); // join it back together<BR>}<BR>//--&#062;&#060;/SCRIPT&#062;<BR><BR>HTML Code for form elements<BR><BR><BR>&#060;body&#062;<BR>&#060;form name="form1"&#062;<BR>&#060;input type="text" name="text1"&#062;<BR>&#060;input type="button" onClick="toUpper()" value="To Upper Case"&#062;<BR>&#060;/form&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;<BR><BR>although it is JAvascript it may give you some ideas...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•