Strings

BlitzMax Forums/BlitzMax Beginners Area/Strings

Replace the function below and type somewhere in your text in the texfield :) or :( or ;) to see how it triggers. Of course if you want some graphics, replace the drawtext command with a drawimage and your own image.

Function TextField1_GA( TextField:TGadget )
	DebugLog "TextField TextField1 was modified"
	DebugLog "Text = "+ TextFieldText$( TextField:TGadget )
	Cls
	DrawText(TextFieldText(TextField),10,10)
	If TextFieldText(TextField).Contains(":)") Then DrawText("Smiley :)",10,50)
	If TextFieldText(TextField).Contains(":(") Then DrawText("Smiley :(",10,80)
	If TextFieldText(TextField).Contains(";)") Then DrawText("Smiley ;)",10,100)
	Flip
End Function


Some useful string functions...
Find:Int( subString:String,startIndex=0 ) Finds first occurance of a sub string. Returns -1 if subString not found.
FindLast:Int( subString:String,startIndex=0 ) Finds last occurance of a sub string. Returns -1 if subString not found.
Trim:String() Removes leading and trailing non-printable characters from a string.
Replace:String( subString:String,withString:String ) Replaces all occurances of subString with withString.
StartsWith:Int( subString:String ) Returns true if a string starts with subString.
EndsWith:Int( subString:String ) Returns true if a string ends with subString.
Contains:Int( subString:String ) Returns true if a string contains subString.
ToLower:String() Converts a string to lowercase.
ToUpper:String() Converts a string to uppercase.
ToInt:Int() Converts a string to an integer.