How print char of string?
Monkey Forums/Monkey Beginners/How print char of string?
| ||
str = FileStream.Open("C:/MonkeyXPro81b/modules/redactor/files/pgrp1.grp", "r") If Not str Print "no" Local i = 0 Local str2:String While Not str.Eof() str2 = str.ReadString() Print str2[2] //Must print"b" but print "69" Wend str.Close End \ where error? |
| ||
Import brl.filestream Function Main:Int() Local str:FileStream = FileStream.Open("C:/MonkeyXPro81b/modules/redactor/files/pgrp1.grp", "r") If Not str Print "no" Return 1 End While Not str.Eof Local str2:String = str.ReadString Print str2[2] ' str2[2] = string indexing: returns a character Print String.FromChar( str2[2] ) ' str2[2] = string indexing: returns a character ' String.FromChar() creates a string from a character Print str2[2..3] ' str2[2..3] = string slicing: returns a substring Wend str.Close Return 0 End Please note that str.ReadString reads the whole file. There is no ReadLine method, so the While..Wend loop isn't required. |