Strings
BlitzMax Forums/BlitzMax Beginners Area/Strings
| ||
I haven't really messed with strings.. I'm looking for some basics on this.. Trying to figure out how to make a notepad like interface using just strings.. I'm using the MaxGUI, I want to add in my text to a txt-field then have it show on a canvas with strings. What I'm trying to do is convert some Text into graphics like "(W)" Makes a Image from that string. Can you let me know. |
| ||
The code below lets you enter your text which is than shown on a canvas. Grab it with grabimage if you like to store it as image... |
| ||
But what if I want to change a set of text like :SAD: into a image like they do on the forums.. |
| ||
I think he means like MSN Messenger etc changes :) into a smiley etc. |
| ||
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. |
| ||
Okay so, what if I wanted the image with in the text itself.. how would I find its position I tried len() |
| ||
If you want to find a position just use find!SuperStrict Local A:String A$="blabla:) and more blabla;)" Print "Position="+A.find(":)") Print "Position="+A.find(";)") If you want to do a Messenger like thing, i would probably store all :) ;) and such as tokens. Also a Tmap may ok, to retrieve the images handles for a certain string “:-)”. Maybe this all too advanced and you like to stick to the old basic commands, you can do so as well: Use Instr( str$,sub$,start=1 ) to find your substring and cut it in pieces with Left$, Right$ and Mid$, check out the docs on this. |