Platforms to show: All Mac Windows Linux Cross-Platform

Back to StringHandleMBS class.

Next items

StringHandleMBS.Add(data as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds data from memoryblock to the string handle.

See also:

StringHandleMBS.Add(data as Ptr, size as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds data from ptr to the string handle with given size.

Using invalid Ptr or size combination can cause a crash.

See also:

StringHandleMBS.Add(data as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds the string at the end of the current data.

Note that all strings added must have the same encoding.

See also:

StringHandleMBS.Add(data as StringHandleMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 22.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds content of other string handle to this one.
Example

Dim s1 As New StringHandleMBS

s1.add "Hello World"

Dim s2 As New StringHandleMBS

s2.add "Got: "
s2.add s1

MessageBox s2.Copy

Just like asking first StringHandle for content as string or Memoryblock and then adding that to the target one. But without the intermediate copying.

See also:

StringHandleMBS.AddByte(value as UInt8)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds a byte to the string handle.

StringHandleMBS.AddInteger(value as Int64)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds a integer value to the string handle.

This is like AddString(str(value)).

StringHandleMBS.Clear

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 21.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Clears the string handle.

Resets size to zero, but does not release memory, so it can be reused.

StringHandleMBS.clone as StringHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new StringHandleMBS object with the same content.

StringHandleMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The constructor of this class.

See also:

StringHandleMBS.Constructor(InitValue as MemoryBlock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 23.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Initializes a StringHandle and inserts the content of the memoryblock.

See also:

StringHandleMBS.Constructor(initvalue as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The second constructor of this class which sets the value directly to the given Xojo string.
Example
// An utility function you can define in a module:

Function BinaryReplaceAll(s as string, a as string,b as string) As string
dim h as StringHandleMBS

h=new StringHandleMBS(s)
h.ReplaceAll(a,b)

Return h.Copy
End Function

See also:

StringHandleMBS.Copy as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns the content as a Xojo string.

This string will have the encoding set in the encoding property.

StringHandleMBS.CopyMemory as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Copies content of handle in new memoryblock.

StringHandleMBS.Delete(start as Integer, lengthBytes as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Deletes the bytes within the range.

One based like RB's string functions.
The start and length parameters use bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.Extract(start as Integer, lengthBytes as Integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns a part of the string.

One based and the returned part is removed form the string data.
The start and length parameters use bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.FindByte(value as UInt8, StartByteOffset as Integer = 1) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds position of a given value.
Example
Dim s As New StringHandleMBS("Hello")

// 64 = big letters
// +32 = small letters
// + 5 = for 5th letter in alphabet

Dim c As Integer = 64+32+5
Dim p As Integer = s.FindByte(c)

MsgBox "position "+Str(p)+" for letter e"

Returns one based byte offset.
Result is 0 if not found.

StartPosition added in v21.3.

See also:

StringHandleMBS.FindByte(values() as UInt8, StartByteOffset as Integer = 1) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 21.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds position of a given value.
Example
Dim s As New StringHandleMBS("Hello Welt")

Dim values() As UInt8
values.append Asc("e")
values.append Asc("o")
Dim p As Integer = s.FindByte(values, 3)

MsgBox "position "+Str(p)+" for letter "+s.Mid(p, 1)

Values is an array of possible values to find.
For best performance avoid duplicates in that array.

Returns one based byte offset.
Result is 0 if not found.

See also:

StringHandleMBS.FirstNonWhiteSpace(StartByteOffset as Integer = 1) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds first non-whitespace byte in the data starting at given offset.
Example
Dim s As New StringHandleMBS("Hello World")
Dim p As Integer = s.FirstWhiteSpace(1)
Dim x As Integer = s.FirstNonWhiteSpace(p+1)

MsgBox "position "+Str(p)+" for white space and "+Str(x)+" for following text"

StartByteOffset is one based.
White space are space, tab and new line characters.
Returns 0 if not found.

StringHandleMBS.FirstWhiteSpace(StartByteOffset as Integer = 1) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finds first whitespace byte in the data starting at given offset.
Example
Dim s As New StringHandleMBS("Hello World")
Dim p As Integer = s.FirstWhiteSpace(1)
Dim x As Integer = s.FirstNonWhiteSpace(p+1)

MsgBox "position "+Str(p)+" for white space and "+Str(x)+" for following text"

StartByteOffset is one based.
White space are space, tab and new line characters.
Returns 0 if not found.

StringHandleMBS.Insert(data as string, position as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Inserts the string data at the given byte position.

One based.
Note that on Unicode the character position and the byte position are not equal!
(On 16bit Unicode charpos=2*bytepos and on US ASCII charpos=bytepos)

The position parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.InStr(OffsetBytes as Integer = 1, target as String, EndOffsetBytes as Integer = -1) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Searches for a binary string inside the StringHandle.
Example
// We test if RB returns the same values as the plugin

dim s as String
dim h as StringHandleMBS

s="Christian"
h=new StringHandleMBS

h.Add s

MsgBox "MBS: "+str(h.InStr("is"))+", RB: "+str(InStr(s,"is"))
MsgBox "MBS: "+str(h.InStr(5,"ia"))+", RB: "+str(InStr(5,s,"ia"))
MsgBox "MBS: "+str(h.InStr("xy"))+", RB: "+str(InStr(s,"xy"))

The same as InStr but with a second parameter to specify the start of the search inside the string handled.

The srcOfs parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

Returns positive value if something is found and zero in case nothing is found.
Returns negative value in case of error.
Casesensitive search!

StringHandleMBS.InStrUTF8(OffsetCharacters as Integer = 1, target as String, EndOffsetCharacters as Integer = -1) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Searches for a binary string inside the StringHandle.
Example
Dim sh As New StringHandleMBS
sh.Encoding = sh.encodingUTF8 // so copy gives right encoding

sh.Add "Ä test Hello Word äöü test string."

Dim s As String = sh.Copy

MsgBox "position of text: "+Str(sh.InStr(5,"test"))+"/"+Str(s.InStrB(5,"test"))+"th byte "+_
"or "+Str(sh.InStrUTF8(5,"test"))+"/"+Str(s.InStr(5,"test"))+"th character"

This function uses UTF8 characters instead of bytes as unit.
Returns positive value if something is found and zero in case nothing is found.
Returns negative value in case of error.
The same as InStrUTF8 but with a second parameter to specify the start of the search inside the string handle.
Casesensitive search!

StringHandleMBS.Left(lengthBytes as Integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns a copy of the first left bytes of the string.

May return less strings if the stored string is not long enough.

The length parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.LeftUTF8(lengthCharacter as integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries given number of characters from string from the left side.
Example
Dim s As String = "Hello öäü!"
Dim d As New StringHandleMBS(s)

d.Encoding = d.encodingUTF8

// ö is two bytes
MsgBox d.LeftUTF8(8)+" in UTF8 and "+d.Left(8)+" in bytes"

StringHandleMBS.Mid(startByte as Integer, lengthBytes as Integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns a part of the string.

One based.
The length parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.MidInteger(startByte As Integer, lengthBytes As Integer = -1) as Int64

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Converts some bytes read as ASCII text to number.
Example
Dim s As New StringHandleMBS("123456789")

Dim v As Integer = s.MidInteger(3,3)
MsgBox str(v)

startByte is one based.

StringHandleMBS.MidUTF8(startCharacter as integer, lengthCharacter as integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries characters from UTF-8 string with given characters.
Example
Dim s As String = "Hello öäü!"
Dim d As New StringHandleMBS(s)

d.Encoding = d.encodingUTF8

// ö is two bytes
MsgBox d.MidUTF8(7,4)+" in UTF8 and "+d.Mid(7,4)+" in bytes"

startCharacter starts with 1 as in Xojo's mid function.

StringHandleMBS.Replace(a as String, b as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Replaces the first string found with content of a with the content of b.
Example
dim s as StringHandleMBS

s=new StringHandleMBS

s.Add "Hallo Leutle, Hellau"

s.Replace("H","h")
s.Replace("l","i")

MsgBox s.Copy+" "+str(s.Len)

Note that all strings are compared binary and must have the same encoding.
Basicly this is just a call to instr, one to delete and one to insert.

See also:

StringHandleMBS.Replace(startpos as Integer, a as String, b as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Replaces the first string found with content of a with the content of b.

If you don't give a startpos parameter the call uses one and is equal to Replace(a,b).
Startpos is one based like all indexes in this class.
The startpos parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

See also:

StringHandleMBS.ReplaceAll(a as String, b as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Replaces all strings with content of a with the content of b.
Example
dim s as StringHandleMBS

s=new StringHandleMBS

s.Add "Hallo Leutle, Hellau"

s.Replaceall("H","h")
s.Replaceall("l","i")

MsgBox s.Copy+" "+str(s.Len)

Note that all strings are compared binary and must have the same encoding.
Basicly this is just a loop with calls to instr, to delete and to insert.

See also:

StringHandleMBS.ReplaceAll(startpos as Integer, a as String, b as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Replaces all strings with content of a with the content of b.

If you don't give a startpos parameter the call uses one and is equal to ReplaceAll(a,b).
Startpos is one based like all indexes in this class.

The startpos parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

See also:

StringHandleMBS.Reverse as StringHandleMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Reverses bytes in string.
Example
Dim s As New StringHandleMBS("Hello")
Dim r As StringHandleMBS = s.Reverse

MsgBox r.Copy

Returns copy of the string with reversed order.

StringHandleMBS.Right(lengthBytes as Integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Returns a copy of the first right bytes of the string.
Example
// There was a small bug in the Right and the Mid function for the version 3.1 of this plugin.
// This test failed in 3.1, but works in 3.2:

dim Text as StringhandleMBS
dim Part as String

Text = New StringHandleMBS
Text.Add "." + chr(13) + chr(10)

Part = Text.Copy
' Now Part is ".<CR><LF" which is correct

if lenb(Part)<>3 then
MsgBox "Failed on Copy "+str(lenb(Part))
end if

Part = Text.Right(1)
' Now Part is "<LF>" which is correct

if lenb(Part)<>1 then
MsgBox "Failed on Right(1) "+str(lenb(Part))
end if

Part = Text.Right(2)
' Now Part is "<CR><LF>" which is correct

if lenb(Part)<>2 then
MsgBox "Failed on Right(2) "+str(lenb(Part))
end if

Part = Text.Right(3)
' Now Part is "" which is wrong!

if lenb(Part)<>3 then
MsgBox "Failed on Right(3) "+str(lenb(Part))
end if

May return less strings if the stored string is not long enough.
The length parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.RightUTF8(lengthCharacter as integer) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries given number of characters from string from the right side.
Example
Dim s As String = "Hello öäü!"
Dim d As New StringHandleMBS(s)

d.Encoding = d.encodingUTF8

// ö is two bytes
MsgBox d.RightUTF8(8)+" in UTF8 and "+d.Right(8)+" in bytes"

StringHandleMBS.Truncate(lengthBytes as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Truncates the string handle content.

Sets the length of the string back to the given value if it's greater.

The length parameter uses bytes not charcters as unit. You can use the Copy method to get a RB string for characterwise editing.

StringHandleMBS.TruncateUTF8(lengthCharacters as integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method String MBS DataTypes Plugin 19.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Truncates data to given number of UTF-8 characters.
Example
Dim s As New StringHandleMBS("äöü")

// limit to 2 characters, here 4 bytes
s.TruncateUTF8 2

MsgBox s.Copy

StringHandleMBS.UInt16Value(offset as Integer) as UInt16

Type Topic Plugin Version macOS Windows Linux iOS Targets
property String MBS DataTypes Plugin 21.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get or set an UInt16 value.
Example
Dim t As String = ConvertEncoding("Hello Welt", encodings.UTF16)
Dim s As New StringHandleMBS(t)

// offset 1 is first character, so second character is offset 3
Dim n As Integer = s.UInt16Value(3)
s.UInt16Value(3) = Asc("a")

MsgBox s.Copy

// append

s.UInt16Value(s.Len+1) = Asc("!")
MsgBox s.Copy

Offset is range checked and may raise an OutOfBoundsException.

When you assign a value and the offset is exactly size of the string handle plus one, we append the new byte.
(Read and Write computed property)

Next items

The items on this page are in the following plugins: MBS DataTypes Plugin.


The biggest plugin in space...