From: francois on
Hi every body,

I would like to make a function in vbs equivalent in
string.title() in Python. Here is some examples :


f("heLLo every bODY!") = "Hello Every Body!
f("it isn't True") = "It Isn'T True"
f(" l'�l�pHAnt blEu-azUr ") = " L'�l�phant Bleu-Azur "


To sum up : UCase() just for the firt letter in a word and
LCase() for the other letters.

Thanks in advance.



--
Fran�ois Lafont
From: francois on
Steve wrote :

> Function ProperCase(Word, FirstLetter, RestOfWord, Pos, Source)
> ProperCase = UCase(FirstLetter) & LCase(RestOfWord)
> End Function
>
> Set EachWord = New RegExp
> EachWord.Pattern = "\b(\w)(\w*)\b"
> EachWord.Global = True
> Set f = GetRef("ProperCase")
>
> WScript.Echo EachWord.Replace("heLLo every bODY!", f)
> WScript.Echo EachWord.Replace("it isn't True", f)
> WScript.Echo EachWord.Replace(" l'�l�pHAnt blEu-azUr ", f)

Thank you Steve for your answer. I have two questions about
this code.

1) I don't knew the "GetRef" function. But where in the
script56.chm documentation can I see the use of this :

Set f = Getref("ProperCase")
string = oRegExp.Replace("it isn't True", f)

If I see your code, I understand the arguments of the
"ProperCase" function, but where is it explained in the
script56.chm documentation. I have read the explation of the
GetRef function in script56.chm, but it isn't enough to
understand your code, especially how can we know the good
number of arguments of the "ProperCase" function.


2) There is a problem with :

Wscript.Echo EachWord.Replace("�l�pHAnt", f)

It gives : "�L�Phant" and I would like "�l�phant".





--
Fran�ois Lafont
From: francois on
Steve a �crit :

> The replacement function part of regular expressions isn't in the help
> file. It was added to regular expressions (both JScript and VBScript) in
> WSH 5.5 and was documented in "What's New in Windows Script 5.5"
> (http://msdn.microsoft.com/en-us/library/ms974619.aspx). As far as I
> know, that is the only place that it is documented. Scroll down to the
> section 'What About VBScript?' for details about using GetRef.

Ok, thanks for the link.


>> 2) There is a problem with :
>>
>> Wscript.Echo EachWord.Replace("�lpHAnt", f)
>>
>> It gives : "�L�Phant" and I would like "�l�phant".
>
> That has to do with Microsoft's definition of the \w metacharacter and
> the \b anchor--it's not language aware and probably doesn't handle
> accented characters very well (although it did correctly find the "�" at
> the beginning of the word). You might have to add some accented
> characters to the pattern: "\b(\w[�...etc.])(\w[...]*)\b".

Ok, but this code doesn't work:

---------------------------------
Function ProperCase(Word, FirstLetter, RestOfWord, Pos, Source)
ProperCase = UCase(FirstLetter) & LCase(RestOfWord)
End Function

Set EachWord = New RegExp
EachWord.Pattern = "\b(\w[�])(\w[�]*)\b"
EachWord.Global = True
Set f = GetRef("ProperCase")
WScript.Echo EachWord.Replace("�l�pHAnt", f)
---------------------------------

It prints "�l�pHAnt". But, I think this code *seems to work
well*:

---------------------------------
Function ProperCase(Word, FirstLetter, RestOfWord, Pos, Source)
ProperCase = UCase(FirstLetter) & LCase(RestOfWord)
End Function
letterWithAccents =
"[a-zA-Z�����������������������������������������������������]"
Set EachWord = New RegExp
EachWord.Pattern = "(" & letterWithAccents & ")" & "(" &
letterWithAccents & "*)"
EachWord.Global = True
Set f = GetRef("ProperCase")

WScript.Echo EachWord.Replace(" l'�l�pHAnt blEu-azUr ", f)
---------------------------------

But, in fact, it's very difficult to be sure that this code
is absolutely correct.

Thanks a lot steve, because, with your help, I have learned
a very usefull thing.




--
Fran�ois Lafont
From: francois on
Just one thing. Is it possible to use Getref with a metod
and not a function? My tests doesn't work.


--
Fran�ois Lafont
From: francois on
francois wrote :
> Just one thing. Is it possible to use Getref with a metod and not a
> function? My tests doesn't work.

It seems to be impossible :

http://msdn.microsoft.com/en-us/library/ekabbe10(VS.85).aspx#ctl00_WikiContent_ctl01_HeaderTitle

What a shame! :-)


--
Fran�ois Lafont