String (gb)

This class provides UTF-8 string manipulation methods.

Aquesta classe és estàtica.

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

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"