comp • gb • string

String (gb)

This class provides UTF-8 string manipulation methods.

This class is static.

Static methods

This is a synonymous of the Pos method.
Byte  
Returns a character from its Unicode value. It is UTF-8 encoded.
Chr  
Returns the Unicode value of a character inside an UTF-8 string.
Code  
Compares two UTF-8 strings, and returns:
Comp  
Returns the position of the first occurrence of Pattern in String.
InStr  
Returns the index of the character at position Pos in the string.
Index  
Return TRUE if String is a valid UTF-8 string.
IsValid  
Returns an UTF-8 string converted to lower case.
LCase  
Returns the Length first characters of an UTF-8 string.
Left  
Returns the length of an UTF-8 string in characters.
Len  
This is a synonymous for the String.LCase method.
Lower  
Returns a substring containing the Length characters from the position Start.
Mid  
Returns the position of the character of index Index in the string.
Pos  
Returns the position of the last occurrence of Pattern in String.
RInStr  
Returns the Length last characters of an UTF-8 string.
Right  
Returns an UTF-8 string converted to upper case.
UCase  
Return the string with its first letter converted to upper case.
UCaseFirst  
This is a synonymous for the String.UCase method.
Upper  

Be careful because standard Gambas string routines only deal with ASCII strings.

To use a non-UTF8 string you must first convert it with Conv$.

Example

Dim hFile As Stream
Dim sOneNonUTF8Line As String
Dim sUTF8Line As String

' Print a WINDOWS-1253 text file to standard output
hFile = Open "/home/ilias/sometextingreekWINDOWS-1253.txt" For Input

While Not Eof(hFile)

  Line Input #hFile, sOneNonUTF8Line
  sUTF8Line = Conv$(sOneNonUTF8Line, "WINDOWS-1253", "UTF-8")
  Print sUTF8Line

  'alternatively
  'LINE INPUT #hFile, sOneNonUTF8Line
  'PRINT Conv$(sOneNonUTF8Line, "WINDOWS-1253", "UTF-8")

Wend

Finally ' Always executed, even if an error is raised
  Close #hFile

Catch ' Executed only if there is an error
  Print "Cannot print or read or convert lines from file "; "/home/ilias/sometextingreekWINDOWS-1253.txt"