| 1 | $String = "'she's all 'that' I,wAnt(" & '1st "disk" of 2)'
|
|---|
| 2 | ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : _StringTitleCase($String) = ' & _StringTitleCase($String) & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
|
|---|
| 3 |
|
|---|
| 4 | ; #FUNCTION# ====================================================================================================================
|
|---|
| 5 | ; Name...........: _StringTitleCase
|
|---|
| 6 | ; Description ...: Changes a string to title case
|
|---|
| 7 | ; Syntax.........: _StringTitleCase($s_String)
|
|---|
| 8 | ; Parameters ....: $s_String - Input string
|
|---|
| 9 | ; Return values .: Success - Returns titlecased string.
|
|---|
| 10 | ; Failure - Returns "".
|
|---|
| 11 | ; Author ........: Jos van der Zande <jdeb at autoitscript dot com>
|
|---|
| 12 | ; Modified.......: BrewManNH
|
|---|
| 13 | ; Remarks .......: This function will capitalize the first character of every word. Modified _StringProper to a titlecase
|
|---|
| 14 | ; function instead of a Proper function. Not Unicode compatible.
|
|---|
| 15 | ; Related .......: _StringProper
|
|---|
| 16 | ; Link ..........:
|
|---|
| 17 | ; Example .......: Yes
|
|---|
| 18 | ; ===============================================================================================================================
|
|---|
| 19 | Func _StringTitleCase($s_String) ; modified _StringProper function, correctly capitalizes after ' and numbers
|
|---|
| 20 | Local $iX = 0
|
|---|
| 21 | Local $CapNext = 1
|
|---|
| 22 | Local $s_nStr = ""
|
|---|
| 23 | Local $s_CurChar
|
|---|
| 24 | For $iX = 1 To StringLen($s_String)
|
|---|
| 25 | $s_CurChar = StringMid($s_String, $iX, 1)
|
|---|
| 26 | Select
|
|---|
| 27 | Case $CapNext = 1
|
|---|
| 28 | If StringRegExp($s_CurChar, "[a-zA-Z\xC0-\xFF0-9]") Then
|
|---|
| 29 | $s_CurChar = StringUpper($s_CurChar)
|
|---|
| 30 | $CapNext = 0
|
|---|
| 31 | EndIf
|
|---|
| 32 | Case Not StringRegExp($s_CurChar, "[a-zA-Z\xC0-\xFF'0-9]")
|
|---|
| 33 | $CapNext = 1
|
|---|
| 34 | Case Else
|
|---|
| 35 | $s_CurChar = StringLower($s_CurChar)
|
|---|
| 36 | EndSelect
|
|---|
| 37 | $s_nStr &= $s_CurChar
|
|---|
| 38 | Next
|
|---|
| 39 | Return $s_nStr
|
|---|
| 40 | EndFunc ;==>_TitleCaseString
|
|---|