MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

Next items

CheckUTF8MBS(data as ptr, size as Integer, Placeholder as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 16.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns string as UTF-8 and replacing invalid UTF-8 sequences with placeholder.
Notes:
This function is more save than simply DefineEncoding as it makes sure the returned text actually is valid UTF-8.
You can replace missing characters with empty text, question mark or any other symbol.

This function is overloaded, so you can directly pass in string, memoryblock or ptr+size.
Checks byte sequence with up to 4 byte long sequences. Does not verify whether code points are valid.

See also:

CheckUTF8MBS(data as string, Placeholder as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 16.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns string as UTF-8 and replacing invalid UTF-8 sequences with placeholder.
Example:
// some random bytes
dim t as string = RandomBytesStringMBS(20, false)

// and some text
t = t + " äöü 😀"

// checked
dim s as string = CheckUTF8MBS(t, "😂")

MsgBox s
Notes:
This function is more save than simply DefineEncoding as it makes sure the returned text actually is valid UTF-8.
You can replace missing characters with empty text, question mark or any other symbol.

This function is overloaded, so you can directly pass in string, memoryblock or ptr+size.
Checks byte sequence with up to 4 byte long sequences. Does not verify whether code points are valid.

See also:

CheckUTF8MBS(mem as MemoryBlock, Placeholder as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 16.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns string as UTF-8 and replacing invalid UTF-8 sequences with placeholder.
Example:
// some random bytes
dim t as string = RandomBytesStringMBS(20, false)

// and some text
t = t + " äöü 😀"

// checked in memoryblock
dim m as MemoryBlock = t
dim s as string = CheckUTF8MBS(m, "😂")

MsgBox s
Notes:
This function is more save than simply DefineEncoding as it makes sure the returned text actually is valid UTF-8.
You can replace missing characters with empty text, question mark or any other symbol.

This function is overloaded, so you can directly pass in string, memoryblock or ptr+size.
Checks byte sequence with up to 4 byte long sequences. Does not verify whether code points are valid.

See also:

ConcatBinaryStringsMBS(a as string, b as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 6.3, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Concats the given strings with binary encoding.
Example:
dim a as string = "Hello"
dim b as string = "World"
dim c as string = ConcatBinaryStringsMBS(a,b)
dim d as string = ConvertEncoding(b, encodings.UTF16)
dim e as string = ConcatBinaryStringsMBS(a,d)

MsgBox "ConcatBinaryStringsMBS"+EndOfLine+EndOfLine+c+EndOfLine+EncodingToHexMBS(c)+EndOfLine+EndOfLine+e+EndOfLine+EncodingToHexMBS(e)
Notes: If RB concats strings the encoding is changed before concating to match the other strings.

See also:

CountOccurancesMBS(s as string, find as string) as Integer
global method, String, MBS Util Plugin (String),
Plugin version: 8.2, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Counts the occurances of a string.
Example:
dim s as string

s="111110001110101010111"

MsgBox str(CountOccurancesMBS(s,"1")) // 14
MsgBox str(CountOccurancesMBS(s,"0")) // 7
MsgBox str(len(s)) // 21
Notes: Returns the number of occurances of a substring in a string.
CreateStringMBS(Length as Integer, Content as String) as string
global method, String, MBS Util Plugin (String),
Plugin version: 16.4, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Creates a string based on a pattern.
Example:
dim c as string = CreateStringMBS(20, "Hello")
dim t as string = CreateStringMBS(10, chrb(255))

Break
Notes:
The content string is repeated until size is matched and returned.
The string returned has the same encoding set as the content string.
DecodingFromHTMLMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 2.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Decodes a string with HTML escaped characters.
Example:
dim html as string = "<p><B>Gr&uuml;&szlig;e</B></P>"
dim htmltext as string = RemoveHTMLTagsMBS(html)
dim text as string = DecodingFromHTMLMBS(htmltext)

MsgBox text // shows: Grüße
Notes:
The source string is converted to a native string if it is not allready in ASCII. Than for every character the functions looks for the unescaped character code and returns a normal unicode string.

e.g. "M&uuml;nchen" -> "München"

This functions uses Realbasic unicode strings, so you may need to convert back to a NativeString before saveing the string to a file. (using e.g. ConvertEncoding(string, encodings.UTF8))

May return "" on low memory conditions.
Strings and encoding work only perfectly for RB 4.5 or newer.

Speed optimized in version 2.8 to be a hundret times faster.
Added Linux support in v5.1.

The result of this function is unpredictable on bad input strings.
(e.g. no encoding, or encoding does not match the content of the string)

Some examples using this method:

Some FAQ entries about this method:

DecodingFromMySQLMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 11.0, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Decodes a string from MySQL.
Example:
MsgBox DecodingFromMySQLMBS("test\\test\%2.doc")
Notes: Replaces all the escapes in a mysql string like (\0, \t or \\) to their binary replacement.
DecodingFromQuotedPrintableMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 3.1, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Decodes a string with quoted printable encoding.
Example:
msgbox DecodingFromQuotedPrintableMBS("Hi, =A1=92")
Notes:
The decoded string is marked to have an ASCII encoding, but you may need to set the encoding to something like ISO. Than you need a text converter to make something printable from it.

May return "" on low memory conditions.
DecodingFromURLMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 2.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Decodes a string with URL escaped characters.
Example:
dim s as string
dim t as string
dim u as string

t="Hello World äöü"

s= EncodingToURLMBS(t,0)

u=DecodingFromURLMBS(s,0)

SetEncodingOfStringMBS u,GetEncodingOfStringMBS(t) // restore encoding

// Hello World äöü
MsgBox t
// Hello%20World%20%C3%A4%C3%B6%C3%BC
MsgBox s
// Hello World äöü
MsgBox u
Notes:
Decodes an URL encoded ASCII string. The string returned is marked as a binary string (without encoding). You need to set the encoding to whatever the original was (ISO-9660 or UTF8 for example).

e.g. "Wie%20geht's%3F" -> "Wie geht's?"

May return "" on low memory conditions.
Strings and encoding work only perfectly for RB 4.5 or newer.
Added Linux support in v5.1.

See also:

DecodingFromURLMBS(s as string, options as Integer) as string
global method, String, MBS Util Plugin (String),
Plugin version: 4.3, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Decodes a string with URL escaped characters.
Example:
dim s as string
dim t as string
dim u as string

t="Hello World äöü"

s= EncodingToURLMBS(t,1)

u=DecodingFromURLMBS(s,1)

SetEncodingOfStringMBS u,GetEncodingOfStringMBS(t) // restore encoding

// Hello World äöü
MsgBox t
// Hello+World+%C3%A4%C3%B6%C3%BC
MsgBox s
// Hello World äöü
MsgBox u
Notes:
Decodes an URL encoded ASCII string. The string returned is marked as a binary string (without encoding). You need to set the encoding to whatever the original was (ISO-9660 or UTF8 for example).

e.g. "Wie%20geht's%3F" -> "Wie geht's?"

May return "" on low memory conditions.
Strings and encoding work only perfectly for RB 4.5 or newer.

Pass 1 for the options parameter to get PHP/Perl compatible output (+ instead of spaces and %20 for spaces).
Added Linux support in v5.1.

See also:

DecodingFromXMLMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 15.2, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Decodes a string with XML escaped characters.
Notes: see DecodingFromHTMLMBS.
DetectUnicodeMarkersMBS(s as string) as Integer
global method, String, MBS Util Plugin (String),
Plugin version: 7.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Tries to get the unicode marker from the string.
Example:
const EncodingUnknown=0
const EncodingUTF8=1
const EncodingUTF16be=3
const EncodingUTF16le=4
const EncodingUTF32be=6
const EncodingUTF32le=7

dim text as string = "Hello World" // this text does not have a marker..

msgbox str(DetectUnicodeMarkersMBS(text))
Notes: For some UTF16 LittleEndian strings this function may return UTF32.
EncodeEmailSubjectMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 14.3, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function:
Encodes an email subject.
Text is encoded with UTF-8 Quoted Printable encoding.
If text does not need to be encoded (pure ASCII), we return the input text.
Example:
MsgBox EncodeEmailSubjectMBS("Hello World")+EndOfLine+EncodeEmailSubjectMBS("Test äöü")

Some examples using this method:

EncodingToHTMLMBS(s as string, options as Integer = 0) as string
global method, String, MBS Util Plugin (String),
Plugin version: 2.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns a string with HTML escaped characters.
Example:
dim f as folderItem
dim b as binaryStream

f=getsaveFolderItem("text/html","new.html")
if f<>nil then
b=f.createBinaryFile("text/html")
if b<>nil then
b.write nativeStringMBS(EncodingToHTMLMBS(editfield1.text))
b.close
end if
end if
Notes:
The source string is converted to unicode if it is not allready in unicode. Than for every character the functions looks for the escaped character code and returns a HTML encoded string.

e.g. "München" -> "M&uuml;nchen"

This functions uses Realbasic unicode strings, so you may need to convert back to a NativeString before saveing the string to a file.

Return characters (chr(10) and chr(13)) are not converted to <BR> codes.

May return "" on low memory conditions.

The result of this function is unpredictable on bad input strings.
(e.g. no encoding, or encoding does not match the content of the string)

Options can be 1 to not encode ASCII values < 128, so quotes, <, > and & are not encoded.

Some examples using this method:

EncodingToQuotedPrintableMBS(s as string, LineLen as Integer = 72) as string
global method, String, MBS Util Plugin (String),
Plugin version: 5.4, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns a string with quoted printable characters.
Example:
dim a as string = "Hello äöü!"
dim b as string = EncodingToQuotedPrintableMBS(a)
dim c as string = ConvertEncoding(a, encodings.ISOLatin1)
dim d as string = EncodingToQuotedPrintableMBS(c)
dim e as string = EncodeQuotedPrintable(a)
dim f as string = EncodeQuotedPrintable(c)

MsgBox b+EndOfLine+d+EndOfLine+e+EndOfLine+f
Notes:
Line wrap is per default at 72 characters but you can pass some other positive value here.
Quoted printable encoded strings have some ISO encoding as base, you need to pass a valid ISO string to this function to get the correct result.
May return "" on low memory conditions.
EncodingToURLMBS(s as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 2.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns a string with URL escaped characters.
Example:
msgbox EncodingToURLMBS("Wie geht's?")
Notes:
Encodings a string for an URL. Use with UTF8 or ISO-9660 encoded strings. This function does not work correctly with UTF16 strings.

e.g. "Wie geht's?" -> "Wie%20geht's%3F"

May return "" on low memory conditions.
Strings and encoding work only perfectly for RB 4.5 or newer.
Added Linux support in v5.1.

See also:

Some examples using this method:

EncodingToURLMBS(s as string, options as Integer) as string
global method, String, MBS Util Plugin (String),
Plugin version: 4.3, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns a string with URL escaped characters.
Example:
dim s as string = "20101210 1244 - Sky Cinema +24 - Wen die Geister lieben"

MsgBox EncodingToURLMBS(s)

// gives: 20101210%201244%20-%20Sky%20Cinema%20+24%20-%20Wen%20die%20Geister%20lieben

MsgBox EncodingToURLMBS(s,1)

// gives: 20101210+1244+-+Sky+Cinema+%2B24+-+Wen+die+Geister+lieben

MsgBox EncodingToURLMBS(s,2)

// gives: 20101210%201244%20-%20Sky%20Cinema%20%2b24%20-%20Wen%20die%20Geister%20lieben
Notes:
Encodings a string for an URL. Use with UTF8 or ISO-9660 encoded strings. This function does not work correctly with UTF16 strings.

e.g. "Wie geht's?" -> "Wie%20geht's%3F"

May return "" on low memory conditions.
Strings and encoding work only perfectly for RB 4.5 or newer.

Pass 1 for the options parameter to get PHP/Perl compatible output (+ instead of spaces and %20 for spaces).
Pass 2 for the options parameter to get plus to %2B and space to %20. Added in plugin version 10.6.

See also:

Some examples using this method:

EncodingToXMLMBS(s as string, options as Integer = 0) as string
global method, String, MBS Util Plugin (String),
Plugin version: 15.2, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns a string with XML escaped characters.
Notes: see EncodingToHTMLMBS.
GetStringsFromDataMBS(data as MemoryBlock, MinLength as Integer = 0) as string()
global method, String, MBS Util Plugin (String),
Plugin version: 16.4, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Looks for strings within a data block.
Notes:
Looks over the bytes in the data block to see if there are useful byte sequences which could be text.
Returns an array with all text fragments found.

This function is UTF8 aware and will work well for UTF-8 encoded text fragments.

See also:

GetStringsFromDataMBS(data as ptr, size as Integer, MinLength as Integer = 0) as string()
global method, String, MBS Util Plugin (String),
Plugin version: 16.4, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Looks for strings within a data block.
Notes:
Looks over the bytes in the data block to see if there are useful byte sequences which could be text.
Returns an array with all text fragments found.

This function is UTF8 aware and will work well for UTF-8 encoded text fragments.

See also:

GetStringsFromDataMBS(data as String, MinLength as Integer = 0) as string()
global method, String, MBS Util Plugin (String),
Plugin version: 16.4, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Looks for strings within a data block.
Example:
dim f as FolderItem = SpecialFolder.Desktop.Child("test.txt")
dim b as BinaryStream = BinaryStream.Open(f)
dim s as string = b.Read(b.Length)
dim texts() as string = GetStringsFromDataMBS(s, 3)

Break
Notes:
Looks over the bytes in the data block to see if there are useful byte sequences which could be text.
Returns an array with all text fragments found.

This function is UTF8 aware and will work well for UTF-8 encoded text fragments.

See also:

GetUnicodeMarkersMBS(kind as Integer) as string
global method, String, MBS Util Plugin (String),
Plugin version: 7.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Returns the unicode marker with the given code.
Example:
const EncodingUnknown=0
const EncodingUTF8=1
const EncodingUTF16=2 // native
const EncodingUTF16be=3
const EncodingUTF16le=4
const EncodingUTF32=5 // native
const EncodingUTF32be=6
const EncodingUTF32le=7

msgbox EncodingToHexMBS(GetUnicodeMarkersMBS(EncodingUTF8))
Notes: If you concat strings, RB may convert the string to UTF8.
HexstringMBS(input as string, hexlen as Integer, linelen as Integer, linestart as string, lineend as string, spacer as string,filler as string) as string
global method, String, MBS Util Plugin (String),
Plugin version: 2.6, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Creates a hexadecimal string.
Example:
dim s as string
s=HexstringMBS("Hello World",2,10,"<",">"+endofline,"","0")
Notes:
Fails if input="" or hexlen<1 or linelen<1 or on low memory conditions.
If filler is "", filler is set to "0".

Memory requirement is around 5 times the memory for input.
or exactly:
mem=20+linelen*hexlen*(1+len(filler))+2*((linelen*hexlen*len(filler)+len(lineend)+len(linestart))*(len(input)*2/hexlen))

All strings must be in the encoding you want to have.
Can raise OutOfMemoryException on low memory.

Some examples using this method:

IsASCIIStringMBS(s as string) as boolean
global method, String, MBS Util Plugin (String),
Plugin version: 7.7, Mac: Yes, Win: Yes, Linux: Yes, Console & Web: Yes, Feedback.

Function: Checks if this string is an ASCII string.
Notes:
False if one of the characters of the string has a numeric value of 128 or higher. (-> string is not a 7 bit ASCII string)
True if all bytes are in the valid ASCII range.

See also:

Next items

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




Links
MBS FileMaker tutorial videos