// Script:         scriptManipulations.ltgs 
// Description:    Examples of string manipulations
// Arguments: 
//		none
//	
// Author : LoopToGo 
 

variable myString "Hello world"

getNbCharacters nbChar $myString

print $myString has $nbChar characters
print	// New line

print Here they are :
print	// New line

for i 1 $nbChar
	getCharacterAt char $myString $i
	convertStringToHex charHex $char

	print At $i : $char hex : [ & $charHex & ]
	
endFor

print	// New line


convertStringToHex strHex $myString

print strhex: $strHex

print	// New line


// Examples with regexReplace (google std::regex_replace for documentation)

// Example 1 : putting voyels in brackets
variable myString "Hello World!"
variable regexPattern "World"
variable regexReplace "good people"

regexReplace regexResult $myString $regexPattern $regexReplace

print regexResult [ $myString ] [ $regexPattern ] [ $regexReplace ]
print regex result: $regexResult
print	// New line


// Example 2 : putting voyels in brackets
variable myString "Hello World!"
variable regexPattern "a|e|i|o|u"
variable regexReplace "[$&]"

regexReplace regexResult $myString $regexPattern $regexReplace

print regexResult [ $myString ] [ $regexPattern ] [ $regexReplace ]
print regex result: $regexResult
print	// New line

// Example 3 : replacing voyels by *

variable myString "Hello World!"
variable regexPattern "a|e|i|o|u"
variable regexReplace "*"

regexReplace regexResult $myString $regexPattern $regexReplace

print regexResult [ $myString ] [ $regexPattern ] [ $regexReplace ]
print regex result: $regexResult
print	// New line

// Example 5 : error message

variable myString "Hello World!"
variable regexPattern "[a-b][a"
variable regexReplace "$1"

regexReplace regexResult $myString $regexPattern $regexReplace

print regexResult [ $myString ] [ $regexPattern ] [ $regexReplace ]
print regex result: $regexResult
print	// New line

// Example 6 : Using $n 
variable myString "its all about bad news"
variable regexPattern "(bad)(.*)"
variable regexReplace "good $2 (not $1 news)"

regexReplace regexResult $myString $regexPattern $regexReplace

print regexResult [ $myString ] [ $regexPattern ] [ $regexReplace ]
print regex result: $regexResult
print	// New line

// Example 6 : Keeping only the first word 
variable myString "Hello my dear!"
variable regexPattern "^(\S+).*"
variable regexReplace "$1"

regexReplace regexResult $myString $regexPattern $regexReplace

print regexResult [ $myString ] [ $regexPattern ] [ $regexReplace ]
print regex result: $regexResult
print	// New line




