CapeSoft.Com
Clarion Accessories
StringTheory
Documentation
CapeSoft Logo

CapeSoft StringTheory
Documentation

Download Latest Version FAQ History Methods
Installed Version Latest Version

Introduction

StringTheory provides simple string handling and manipulation, including dynamic memory allocation (the string is always the correct length, and any amount of data can be added to it), fast and simple string parsing

StringTheory will easily help you: StringTheory provides Unicode support in the form of UTF-8, as well as converting between ANSI and UTF-8 strings

We strongly recommend starting with the example applications, which are described below in the Example section.

Features

StringTheory provides dynamic memory allocation, string handling and manipulation, conversion between string and cstring data types, base64 encoding and decoding, file loading and saving, and much more.

See the Class Reference for a list of all methods and properties provided.

Using StringTheory in an APP

Add StringTheory to your application in a few Easy Steps!

Add the global and local extension

Using the StringTheory Class

The code below demonstrates using the StringTheory class for a variety of common tasks.

In general a StringTheory object is declared as simply as

st StringTheory

Where st is the label name (and can be almost anything.) The length of the string is undefined, and is dynamic. In other words the string will automatically grow, and shrink as required. You do not need to worry about the length.

Values are assigned into the string using the SetValue method, or by loading a file off the disk using the LoadFile method.

st.SetValue('hello world')

st.LoadFile('c:\windows\win.ini')

After that the string can be manipulated in a number of different ways, using the methods described in the Class Reference. For example to Base64 encode the string;

st.Base64Encode()

Using StringTheory in a Hand-Coded Project

To add StringTheory to a hand-coded project (with no APP and hence no Global Extension template) do the following;
  1. Add
    include('StringTheory.Inc'),Once
    to your main module
  2. Add the StringTheoryLinkMode and StringTheoryDllMode project defines to your project. Set
    StringTheoryLinkMode=>1
    if the class should be linked into the project, and
    StringTheoryDllMode=>1
    if the object is exported from another DLL.
  3. If you will be using the md5 function in StringTheory then add
    ojmf5.c
    to the modules to be compiled by your project, and set the project define
    MD5=>1

You can declare StringTheory objects in your code by simply doing;

str   StringTheory

Overriding or deriving StringTheory methods is not usually necessary.

Distribution

If you use the Gzip or Gunzip methods in your application then you will need to distribute the ZLIBWAPI.DLL with your application. This DLL is located in your \3rdparty\bin or \accessory\bin folder, and is also available from the official source at http://www.winimage.com/zLibDll/index.html. The Zlib library home can be found here http://www.zlib.net.

ZLIB is the product of Jean-loup Gailly and Mark Adler and is distributed under the terms of their license at http://www.zlib.net/zlib_license.html .

Example

Demo

This is the main StringTheory example application. It demonstrates a variety of common and useful tasks using the StringTheory class.

Some Ideas and Suggestions

Check password strength

st.SetValue(Password)
if st.ContainsA('0123456789') = false
    Message('Needs a number')
end
if st.ContainsA('ABCDEFGHIJKLMNOPQRSTUVWXYZ') = false
    Message('Needs one or more upper case characters')
end
if st.ContainsA('abcdefghijklmnopqrstuvwxyz') = false
    Message('Needs one or more lower case characters')
end
if st.IsAll('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') = true
    Message('Must contain at least on non-alphanumeric character')
end
if st.Length() < 16
    Message('Must be at least 16 characters long')
end

Parsing a CSV File

One common use for StringTheory is to parse text files for import. One of the more common text file formats is Comma-Separated-Values, more commonly known as CSV. To effectively parse a CSV file two StringTheory objects are used - one to parse the file into rows, and the other to parse a single row into columns.
Using StringTheory in this way is a lot faster than using the ASCII or BASIC drivers, but since the whole file is loaded into Ram at the start, this approach
consumes more working memory.
The key to this approach is using the Split method.

str   StringTheory
lne   StringTheory
x     Long
  code
  str.LoadFile('Somefile.CSV')
  str.Split('<13,10>')
  loop x = 1 to str.Records()
    Lne.SetValue(Str.GetLine(x))
    Lne.Split(',','"','"',true)
    field1 = Lne.GetLine(1)
    field2 = Lne.GetLine(2)
  End


A variation on this is a tab-separated file which uses the tab character instead of a comma to separate the fields. The onle change to the above code would be the second Split, which becomes:

    Lne.Split('<9>','"','"',true)

Prime GUID fields

For various reasons the use of randomly generated strings as primary key values is becomeing more common. StringTheory allows you to easily prime these fields in the dictionary (which in turn is then applied by the Templates in the PrimeRecord method.)

  1. Create a global variable section in the dictionary. For purposes of this example assume the prefix is set to glo .
  2. Create a global variable inside this section called ST. Set the "Data Type" to Type and set the "Base Type" to StringTheory.
  3. Create a field called GUID in the necessary tables. A string(16) is the ideal type for this. Set the initial value to glo:st.MakeGuid() .
MakeGuid is a specific form of the Random method. If you like, you can use a call to Random here instead of MakeGuid with a different length or alphabet.

File Name Manipulation

There are four methods in StringTheory that make handling file names easier.

Placing a complete file name in a StringTheory object allows you to access the various parts of the file using the methods FileNameOnly, PathOnly and ExtensionOnly. For example;

str.SetValue('c:\temp\strings\table.tps')
Path = str.PathOnly()
FileNameWithExtension = str.FileNameOnly()
FilenameNoExtension = str.FileNameOnly( , false)
Extension = str.ExtensionOnly()


Alternatively you can pass the full path into the various methods. This will allow you to use an existing string, or path name, instead of first assigning it to the string. For example;

Path = str.PathOnly(NAME(Customers))

This would return the path location of the Customers TPS file.

Another useful value is COMMAND(0) Which returns the path, and name of the current EXE. So

ExeName = str.FileNameOnly(COMMAND(0))

The CleanFileName method is useful for checking a filename after the user has entered one. This checks that the filename only contains valid characters, and removes any invalid characters. For example

str.SetValue(someName)
str.CleanFileName()



Upgrading

NetTalk 7, Cryptonite, RunScreen and OddJob all depend on StringTheory. If you use any of these, and you update to StringTheory 2.00 or later then you will need to use NetTalk / NetTalk Lite 7.35 (or later), Cryptonite 1.63 or later and/or OddJob 1.36 or later.

StringTheory 2 is very backwards-compatible with StringTheory 1.xx and it is probable that you will need to make no changes to your application. There is however one change which may be significant to your program.

StringTheory 1 contains a property, a pointer to the string itself, called Value. In most cases you would not needed to have used this property, however occasionally when a string pointer is required (for example to pass to a function) you may have used it directly.

In order to determine where the property is used directly, the property itself has been change to Private. This will cause a compile error;

Invalid use of PRIVATE Data

If you are not getting this error then there is nothing for you to do. If you are getting this error then replace this with a call to .GetValuePtr()

For example

  whatever(str.value)

becomes

  whatever(str.GetValuePtr())

It is possible to make two small changes to the StringTheory INC and CLW files, and by doing so return StringTheory to Version 1 behavior. This is not recommended, but may be useful if you are having a problem upgrading.
  1. Remove the ,PRIVATE attribute from the value property in StringTheory.Inc.
  2. Remove the line self.UseBuffer = true from the Construct method in StringTheory.Clw
Note that if you are using NetTalk 7, you will need version 7.36 or later which is compatible with StringTheory 2. Versions 1.35 and earlier are not compatible. If you wish to use an older version of NetTalk then make the changes to StringTheory discussed above.

Advanced

It is possible you were doing string-slicing on the value property directly. Since the Value property is now private, this code will fail with the same error as mentioned above. While you will still have to change your code, there is a new property, valueptr, which can be used in place of value. Note that you should only use valueptr if you are sure that your code is correct. Using it directly can cause problems if the appropriate checks are not done.

For example;

str.value[4] = 'a'

becomes

str.valueptr[4] = 'a'

FAQ's

Check out general product CompilerErrors.

Compile Errors

  1. Source File ojmd5.c not found 
    You have no *.c entry in your red file. Re-run the installer, taking care to check the "Update Clarion Redirection file" checkbox.
  2. Invalid use of PRIVATE Data
    See Upgrading.

The StringTheory Templates

The Global Extension Template

There are no options for the Global extension.

The Local Extension Template

Add this extension to populate an instance of the StringTheory class for you. This can also be done very simply in your code:

st StringTheory
  code
  st.SetValue('Some Value')

Acknowledgements

StringTheory includes some code originally appearing in a StringClass, written by Rick Martin and published in ClarionMag and is used with permission.

Many thanks to Geoff Robinson for ongoing feedback and contributions to StringTheory, including bug fixes, improvements and new methods!

ZLIB is the product of Jean-loup Gailly and Mark Adler and is distributed under the terms of their license at http://www.zlib.net/zlib_license.html

Class Reference - StringTheory

StringTheory Class Reference Introduction

The StringTheory class provides a full string handling class that dynamically allocates memory as needed and provides a wide variety of string handling and manipulation methods, including:

Using the StringTheory Class

In general a StringTheory object is declared as simply as

st StringTheory

Where st is the label name (and can be almost anything.) The length of the string is undefined, and is dynamic. In other words the string will automatically grow, and shrink as required. You do not need to worry about the length.

Values are assigned into the string using the SetValue method, or by loading a file off the disk using the LoadFile method.

st.SetValue('hello world')

st.LoadFile('c:\windows\win.ini')

After that the string can be manipulated in a number of different ways, using the methods described below. For example to Base64 encode the string;

st.Base64Encode()

StringTheory Method Reference

AbbreviateTruncate a string, searching for a natural break point if possible.
AddBOMAdd a byte-order-mark (BOM) to the front of the string (usually right before saving to disk.)
AfterReturns the rest of the string after a delimiter.
AllReturns the current string, repeated until the returned value is a specific length.
AppendAppend a value to the end of the string
AppendBinaryAppend a (long / short / byte) to the end of the string, but as binary characters.
AsnDecodeTake a AsnEncoded value and split it into the component parts.
AsnEncodeTake a string value, and encode it according to ASN rules.
AsnEncodeNumberTake a number and encode it according to ASN ruiles.
BeforeReturns the section of the string before a delimiter.
BetweenReturns the string between the passed delimiters if it exists. Also see FindBetween which returns the start and end positions and allows multiple strings to be located and returned between the same delimiters .
Base64DecodeDecode a string that is encoded using Base64
Base64EncodeEncode the string using Base64 encoding method
Capitalize Capitalizes the first letter in one or more words in the string.
CharsReturns the number of Characters in the string (not the number of bytes). Works for strings in ANSI, Utf-8 or Utf-16 encodings.
CleanFileNameCleans and returns a file name with any invalid characters replaced.
ClipClips the string (removed trailing whitespace)
ClipLengthGet the length of the string, ignoring trailing spaces
ColorToHexconverts a Clarion RGB color stored in a long to a hex string (which can be used in CSS, HTML etc.).
ColorFromHexconverts a string containing the hexadecimal representation of the color to a long containing a standard RGB Clarion color
ContainsAReturns true if the string contains at least one character from a matching alphabet.
ContainsADigitReturns True if the string contains at least one digit character ('0' to '9')
CountReturns the number of times that the Search Value appears in the current string
CountWordsReturns the number of words in the string. Also see WordStart and WordEnd.
CropRemoves part of the string from either the front, or rear, or both, of the string
DecEntityToCharConverts the for &#nnn; into a character.
EndsWithChecks to see if the string ends with a substring.
EqualsCompares one StringTheory object with another StringTheory object.
ErrorTrapCalled if an OS error occurs
ExtensionOnlySplits the extension part out of a file name.
FileNameOnlySplits the file name part out of a fully qualified path name
FormatMessageInterprets the windows API error code
FreeClears the string and returns all the memory used by the string
FindCharFast brute force find a single character
FindCharsFast brute force find for a substring
FindBetweenFinds and returns a string between the passed start and end delimiters and returns the start and end position of the string found.
FindWordRetrieve the word at the specified position from the string, and returns the position of the word as well.
FromBlobRetrieves the data from the passed BLOB and stores it.
GetValueReturns the current value of the string
GetValuePtrReturns a pointer to the current value of the string.
GetWordSee Word.
HtmlEntityToDecConverts the form &acute; into a character
HostOnlySee UrlHostOnly.
InsertInserts a passed string into the stored string at the specified position
InstringSearch for a string in a sub string
IsAllReturns true if the string only contains specific characters.
IsAllDigitsReturns True if the string contains only digit characters ('0' to '9')
IsTime Returns true if the string looks like a formatted time value.
JsonDecodeConverts a string that was encoded for transport in JSON format.
JsonEncodeEncodes a string into JSON format, suitable for adding to a JSON packet.
KeepCharsRemoves all non-specified characters from the string.
LeftReturns the non-space characters from the left of the string.
LengthThe current length of the string
LineEndingsChange <13,10> to <13> or <10> or vice versa.
LoadFileLoad a file off the disk into the string
LowerChange all the characters in the string to be lower case
MakeGuidCreate a random string suitable for a unique identifier.
MatchBracketsFind the matching end bracket in a string.
MD5Generates the MD5 Hash of a string
MergeXMLMerge a new XML node into an existing XML document.
NormalizeNormalizes a string reducing it to a form suitable for comparisons.
PathOnlyGets the path part of a fully qualified file name
PrependAdds a sub string to the front of the string
QuoteAdds the specified "quotes" to the stored (wraps the string in the passed quotes).
RandomFills the string with random characters
RemoveRemove some text from the string.
RemoveAttributesRemoves the attributes from an HTML tag.
RemoveCharsRemoves all specified characters from the string.
RemoveXMLPrefixesRemoves all prefixes from inside xml tags.
ReplaceReplaces one, or more, instances of the search string with a new value
ReverseReverses the contents of the string so the first byte is last and so on.
RightReturns the non-space characters from the right of the string.
SaveFileSaves the current string to disk
SerializeGroupConverts a group to a (something) delimited string.
SerializeQueueConverts a Queue to a (something) delimited string.
SetAllRepeats the contents of the current string, until the string is a specific length.
SetEncodingFromBOMAfter loading a file, sets the encoding property based the Byte-Order-Mark (if one exists.) Optionally removes the BOM.
SetLeftRemoves leading spaces, and possibly limits the length of the string.
SetLengthSets the length of the string
SetRightAdds leading spaces so the string is the specified length, but has no trailing spaces.
SetValueAssigns a new value to the current string
SetSliceSets the value of a substring within the stored string
SliceReturns a substring of the current string
SortSorts the contents of a string.
SplitSee Split, Manipulate and Join Strings
SqueezeRemoves additional white space from between words in the string (word will be separated by only a single space after calling squeeze).
StartReset all properties back to the default to reuse the object.
StartsWithChecks to see if the string starts with a substring.
SubReturns a substring of the current string
StrReturns the current string and optionally stores the passed value.
ToAnsiConverts the current Unicode (UTF-8 or UTF-16) string to ANSI
ToCStringCreates a CString and copies in the current string value
ToBlobSaves the data stored by the StringTheory object in the passed BLOB.
ToUnicodeConverts the current ANSI string to Unicode (either UTF-8 or UTF-16)
TraceSends a string to the DebugView program for logging
TrimRemoves whitespace from the start and the end of the string
UnQuoteRemoves quotation marks (or the specified values) from the start and end of the string.
UpperConverts all the lower case characters to upper case
UrlEncode Method URL (percent) encodes the passed string
UrlDecodeMethods decodes the passed URL (percent) encoded string.
UrlFileOnlyExtracts the Filename part of a URL
UrlHostOnlyExtracts the Host part of a URL
UrlParameterReturns the value of a single parameter from a URL.
UrlParametersOnlyExtracts the Parameters part of a URL
UrlPathOnlyExtracts the Path part of a URL
UrlPortOnlyExtracts the Port part of a URL
UrlProtocolOnlyExtracts the Protocol part of a URL
WordRetrieve the word at the specified position from the string.
WordEndReturns the end position of the next word in the string given a start position to begin searching from.
WordStartReturns the start of the next word in the string given a starting position to being search from.
WrapTextperforms word wrapping to wrap the text to a fixed width by breaking lines as close the the specified width as possible. Lines are only broken on white space (tabs and spaces). The default wrap width is 80 characters.
XMLDecodeDecodes a string that was encoded for transport in XML format.
XMLEncodeEncodes a string into XML format, suitable for adding to an XML packet.
Split, manipulate and Join strings
SplitSplits the string into parts based on the specified delimiters
SplitEverySplits the string into substrings of the specified length.
SplitIntoWordsSplits the string into a queue of words.
JoinCreates a string from the separate lines (where the lines are made by Split)
AddLineAdds a line to the line queue, at a specific position.
DeleteLineDeletes a line from the line queue.
FreeLinesFrees the Queue populated by the Split method
GetLineGets a specific line after a call to the Split method
InLineSearches the lines for a specific substring
RecordsReturns the number of records after a call to the Split method
RemoveLinesRemove empty lines, or lines which only contain specific characters.
SetLineSets the Value of a specific line in the queue
SortSorts the lines alphabetically
FilterRemove some lines, based on the presence, or absence, of a string on that line.
Formatting and Deformatting
FormatTimeFormats a number (Clarion standard time) into a String
DeformatTimeFormats a string into a number (Clarion Standard Time)
Base Conversion, Hexadecimal encoding and Byte Ordering
ToHexConverts the stored string to a hex string - each bytes is converted to two characters representing the hexadecimal equivalent.
FromHexConverts a string that is encoded as a hex string back to the original value.
DecToBaseConverts a decimal number to a number using the specified base (such as Hexadecimal - base 16)
BaseToDecConverts the passed number stored in a string to a decimal
ByteToHexReturns a string that contains the hexadecimal equivalent of the passed byte
LongToHexConverts a long of 4 bytes to hex. Returns a string that contains the hex of each byte in big endian order (the most significant byte first)
StringToHexReturns a string that contains the hexadecimal equivalent of each byte in the passed string (which is treated as binary data).
HexToStringDecodes the passed hex string and returns a pointer to a new string that contains the unencoded data.
BigEndianReturns a big endian long when passed a little endian one
LittleEndianReturns a little endian long when passed a big endian one
SwitchEndianSwitches between big endian and little endian (returns a little endian long when passed a big endian one and vice versa).
ReverseByteOrderReverse the byte order of the stored string (the entire string is reversed).
Unicode Encoding, Conversion and Handling
ToAnsiConverts the current Unicode (UTF-8 or UTF-16) string to ANSI
ToUnicodeConverts the current ANSI string to Unicode (either UTF-8 or UTF-16)
AnsiToUtf16Converts the pass ANSI string to UTF-16 encoded Unicode
Utf16ToAnsiConverts the passed UTF-16 encoded Unicode string to ANSI
Utf8To16Converts UTF-8 to UTF-16
Utf16To8Converts UTF-16 to UTF-8
Utf16ToUtf8CharConverts a Utf-16 (2 byte) character to a (1 to 3 byte long) Utf-8 character
Utf8ToAnsiConverts the passed UTF-8 encoded Unicode string to ANSI
AnsiToUtf8Converts the passed ANSI string to UTF-8 encoded Unicode
DecodeHexInlineConverts text encoded with \x or \u in an ANSI string into the appropriate character
BigEndianMakes sure the string (if utf-16) is in BigEndian form.
LittleEndianMakes sure the string (if utf-16) is in LittleEndian form.
Other Encodings
Base64DecodeDecode a string that is encoded using Base64
Base64EncodeEncode the string using Base64 encoding method
EncodedWordDecodeDecodes the string if it's encoded in "Encoded Word" format.
EncodedWordEncodeEncodes the string to "Encoded Word" format.
ToHexConverts the stored string to a hex string - each bytes is converted to two characters representing the hexadecimal equivalent.
FromHexConverts a string that is encoded as a hex string back to the original value.
HtmlEntityToDecConverts HTML Entity names to Unicode Decimal encoding.
JsonDecodeDecodes a string that was encoded for transport in JSON format.
JsonEncodeEncodes a string into JSON format, suitable for adding to a JSON packet.
QuotedPrintableEncode Encodes the string to QuotedPrintable Format.
QuotedPrintableDecode Decodes the string from QuotedPrintable format.
UrlEncode Method URL (percent) encodes the passed string
UrlDecodeMethods decodes the passed URL (percent) encoded string.
XMLDecodeDecodes a string that was encoded for transport in XML format.
XMLEncodeEncodes a string into XML format, suitable for adding to an XML packet.
Binary Data handling and storage
FromBytesConverts a value stored as binary within a string back into the native data type (for example retrieving a Long value from a String). Prevents any automatic type conversion and retrieves the actual binary value stored in a string for the following types: byte, short, ushort, long, ulong, sreal, real, decimal, cstring, string
ToBytesStores the passed value in a string as binary. Does not do any type conversion - the data is stored as a sequence of bytes with the same values as in the original. Support the following types: byte, short, ushort, long, ulong, sreal, real, decimal, cstring, string
GetBytesRetrieves a binary value stored in the StringTheory object.
SetBytesStores a binary value in the StringTheory object.
Compression and Decompression
GzipCompress the string to the .gz (gzip) format using the external zlibwapi.dll.
GunzipDecompress the string from the .gz (gzip) format using the external zlibwapi.dll
NOTE: To make use of the GZIP and GUNZIP methods, you must copy the ZLIBWAPI.DLL into your application folder.

Abbreviate

Abbreviate(Long pPos, Long pRangeLeft = 15,Long pRangeRight = 15)

Description

Shortens a string by searching for a space character "near to" the requested length. Useful for shortening text, but having the abbreviated text end on a complete word. If no space can be found in the range, then the string is simply clipped at the requested position. The method looks in both directions (within the bounds set) to find the closest space.

Parameters
Parameter Description
pPosThe desired length of the string.
pRangeLeftThe number of characters to examine, left of the desired position. 
pRangerightThe number of characters to examine, right of the desired position. If the pPos value is an upper-bound then set this parameter to 0.
Return Value

Returns the length of the resultant string. The contents of the string object are modified with the shortened string.

See also

Sub

AddBOM

AddBOM(Long Encoding=-1)

Description

Adds a Byte-Order-Mark (BOM) to the front of the string, based on the current string encoding (or the passed parameter.) Byte order marks are often added to the beginning of text files to indicate to editors if the file contains characters in the utf-8 or utf-16 format. If an incorrect BOM already exists then it is removed. If the correct BOM already exists the the string is not changed.

Parameters
Parameter Description
Encodingthe encoding to use. Valid values are st:EncodeUtf8 or st:EncodeUtf16. If omitted then the current encoding (as set in the encoding property) is used.
Return Value

Returns nothing. The String may be altered.

See also

SetEncodingFromBOM

After

After (string SearchValue, long Start=1, long End=0, long NoCase=false)

Description

Returns the contents of the current string after a delimiter.

Parameters
Parameter Description
SearchValueSearches for this string in the current string, and returns all the text after this string (not including this string).
Start (optional)The start position in the current string to start the search. If omitted the search will start at the beginning of the current string.
End (optional)The position in the current string to end the search. If omitted then the search will end at the end of the current string.
NoCase (optional)If set to true the search value is case insensitive. By default the search value is assumed to be case sensitive.
Return Value

Returns the contents of the current string after a delimiter. If the search string is not found then a blank string is returned.

See also

Before

All

All (long Length=255))

Description

Repeats the current contents of the string until the string is Length characters long. This method does not affect the current string value. To change the current value use the SetAll method.

Parameters
Parameter Description
LengthThe length of the resultant string.
Return Value

The current string contents, repeated so the returned value is Length characters long.

See also
SetAll

Append

Append (string NewValue, <Long pClip=st:NoClip>, <String pSep>)
Append (stringTheory pStr, <String pSep>)


Description

Appends the NewValue to the current string currently stored in the object.

Parameters
Parameter Description
newValueThe value to append to the string
pClip This can be one of several options.
st:NoClip - The current value is not clipped before the NewValue is appended.
st:Clip - The current value is clipped before the NewValue is appended
st:NoBlanks - If the NewValue is blank, then the pSep parameter is not added to the string.
st:Clip + st:NoBlanks- the string is not clipped, and the separator is not added if NewValue is blank.

Note
: Only text data should be clipped. Clipping binary data is not recommended.
pStr Another StringTheory object. If this form of the method is used then the contents of pStr will be appended to the current object.
pSepIf the string already contains text, then the optional Separator is added between the existing text, and the new text. If the string is currently blank then the separator is ignored. The separator is not clipped (thus allowing for space separators) so care should be taken with the string being passed.
Return Value

None

See also

Prepend , SetValue

AppendBinary

AppendBinary (long Value,Long Length=4)

Description

A string is placed over the Value parameter, and that string is appended to the end of the current value. The number of bytes appended is passed in the optional Length parameter.

Parameters
Parameter Description
ValueThe value (in number form) to append to the string
Length The number of bytes to append to the string. Use 1 for a byte, 2 for a short, or 4 (the default) for a long.
Return Value

None

AsnDecode

AsnDecode(*Long pPos, *StringTheory rAsnValue, <*String rAsnType>)

Description

Abstract Syntax Encoding (ASN) encoding is a variable-length way of encoding multiple data fields,  consisting of three parts - a type, a length and a value. This method takes a string, which contains an ASN encoded value, and splits it into those  three parts.

Note that the rAsnValue is raw bytes. If, for example, the type is an integer then the value returned is not a number, but some raw ASCII bytes. Also be aware of the length - integers might be 1, 2 or 4 bytes long. Check rAsnValue.Length() to know which it is.

Parameters
Parameter Description
pPosThe position in the current string to extract from. Only the first ASN value found, starting at this position is extracted. This field is altered to point at the first character after the extracted value.
rAsnValue The raw data in the Value part of the encoding.
rAsnType A string, length 1 or more, to contain the TYPE of the field extracted. the type returned is always 1 character long. Some common types are declared in the Stringtheory.Inc file, however this list is not exhaustive. For example;
st:ASN_BOOLEAN     Equate('<01h>')
st:ASN_INTEGER     Equate('<02h>')
st:ASN_BITSTRING   Equate('<03h>')
st:ASN_OCTETSTRING Equate('<04h>')


This parameter is optional and can be omiited if the type is not required.
Return Value

st:ok if the decoding was successful. st:notok if there was a problem. The original string value in the object is not altered. A value of st:NotOk usually means the data was "short" - ie did not include the number of bytes as indicated by the length.

Example

str  StringTheory
Pos  Long
DecodedType  String(1)
Decoded  StringTheory
  code
  str.SetValue(someASNencodedvalue)
  pos = 1
  str.AsnDecode (pos,Decoded,DecodedType) ! Decoded now contains the ASN value.


See Also

AsnEncode, AsnEncodeNumber

AsnEncode

AsnEncode(String pType, <String pValue>)

Description

Abstract Syntax Encoding (ASN) encoding is a variable-length way of encoding multiple data fields,  consisting of three parts - a type, a length and a value. This method adds the length, and type to the front of the existing string. If a value is passed then that is assigned to the string object before the encoding.

Note that the string value is "raw bytes". To encode a number use the AsnEncodeNumber method.

Parameters
Parameter Description
pTypeThe ASN Type to use. This is a String 1. Some basic types are declared in StringTheory.Inc, however other type values may also be used depending on the program creating or consuming the type.
pValue An optional parameter. If this parameter is omiited then the current string in the object will be used. Strings of zero length are allowed in ASN.
Return Value

Nothing. The object is updated with the new value.

Example

str  StringTheory
  code
  str.SetValue('NetTalk is cool')
  str.AsnEncode (st:ASN_OCTETSTRING) ! str now contains the ASN type, length and value.


See Also

AsnDecode, AsnEncodeNumber

AsnEncodeNumber

AsnEncodeNumber(String pType, Long pValue)

Description

Abstract Syntax Encoding (ASN) encoding is a variable-length way of encoding multiple data fields,  consisting of three parts - a type, a length and a value. This method adds the length, and type to the front of the existing string. A number is passed (as a value) and ths is converted into binary before adding it to the string.

Parameters
Parameter Description
pTypeThe ASN Type to use. This is a String 1. Some basic types are declared in StringTheory.Inc, however other type values may also be used depending on the program creating or consuming the type. A number of the types are numeric, for example;
st:ASN_BOOLEAN      Equate('<01h>')
st:ASN_INTEGER      Equate('<02h>')
st:ASN_ENUMERATED   Equate('<00Ah>')
pValue The number to encode.
Return Value

Nothing. The object is updated with the new value.

Example

str  StringTheory
  code
  str.Asnencode (st:ASN_INTEGER,1234) ! Str now contains the ASN value.


See Also

AsnDecode, AsnEncode

Before

Before (string SearchValue, long Start=1, long End=0, long NoCase=0)

Description

Returns the contents of the current string before a delimiter.

Parameters
Parameter Description
SearchValueSearches for this string in the current string, and returns all the text before this string (not including this string).
Start (optional)The start position in the current string to start the search. If omitted the search will start at the beginning of the current string.
End (optional)The position in the current string to end the search. If omitted then the search will end at the end of the current string.
NoCase (optional)If set to true the search value is case insensitive. By default the search value is assumed to be case sensitive.
Return Value

Returns the contents of the current string before a delimiter. If the search string is not found then a blank string is returned.

See Also

After

Between

Between (string Left, string Right, long Start=1, long End=0, long NoCase=0, long Exclusive=1)

Description

Return the part of the string between two search strings (by default exclusively, i.e. the Left and Right delimiter are not included in the returned string). The FindBetween method performs the same functionality but also sets the passed Start and End to the position in the string that the returned string was found at, which allows for repeated calls to FindBetween to find multiple substrings using the same delimiters.

Parameters
Parameter Description
LeftThe left hand delimiter. If this is blank then the start of the string is used.
RightThe right hand delimiter. If this is blank then the end of the string is used.
Start [optional]If this is specified then the search for the delimiter starts at this position in the string. Defaults to the start of the string.
End [optional]If this is specified then the search ends at this position in the string (delimiters after this are ignored). Defaults to the length (end) of the string.
NoCase [optional]If this is set then the delimiter search is case insensitive, otherwise it is case sensitive.
Exclusive [optional]If this is set to true (the default) then the delimiters are not included in the returned string. If it is set to false then they are included in the returned string.
Return Value

Returns the string between the passed delimiters if it is found, otherwise a blank string is returned. Between does not alter the original string.

See also

FindBetween

Base64Decode

Base64Decode ()

If the Base64 property is set to True, then decodes the current string using the Base64 decode algorithm. The Base64 property is then set to False.

Parameters

None

Return Value

None

See Also

Base64Encode

Base64Encode

Base64Encode (Long pNoWrap=0)

Description

If the Base64 property is false, then encodes the current string in Base64 format. The Base64 property is set to True.

By default lines are wrapped by inserting a carriage return, line feed pair (ASCII 13,10) to limit the line length to 80 characters including the CR,LF pair. To disable automatic line wrapping set the base64NoWrap property to True (1) before calling Base64Encode.

Parameters

Parameter Description
NoWrapIf set to true then the output will not be wrapped. Usually the output is wrapped at around the 80 character mark. Set it to st:NoWrap to force the output string not to wrap.

Return Value

None

Example

st StringTheory
  code
!-------------------------------------------------------
! Example 1: Base 64 encode a string (which may contain binary data) with
! the default line wrapping.
!-------------------------------------------------------

  st.SetValue(binaryVal)       
! Set the value, can be binary data
  st.Base64Encode()            
! Base64 encode (automatically line wraps)
  base64String = st.GetValue()
 ! Store the Base64 encode value (which is now a plain text string)

!-------------------------------------------------------
! Example 2: Load a file and Base64 encode the contents with
! line wrapping disabled.
!-------------------------------------------------------

  st.LoadFile(myFileName.jpg)
! Load a file (can be binary)
  st.base64NoWrap = true     
! Disable line wrapping
  st.Base64Encode()
  encodedFile = st.GetValue()
! Get the Base64 encode file as a string

See Also


Base64Decode

Capitalize

Capitalize(long pCount=1, long pStartPos=1, long pEndPos=0, <String pCharlist>)

Description

Capitalizes the first letter of one, or more, words in the string. Does not affect other letters in the string. Specifically does not "lower" any characters in the string.

Parameters
Parameter Description
pCountThe maximum number of words to Check. (Not this is NOT the maximum number of words to Change.) Defaults to 1 - ie only the first word in the string will be Capitalized. Set it to 0 to capitalize all words.
pStartPosThe position in the string to begin. Defaults to the start of the string.
pEndPosThe position in the string to end. Defaults to the end of the string.
pCharListThe list of characters which specify the end of a word. The default value is '. <13><10><9>,-;"''!?&()*/+=<>:'
Return Value

Noting. The string currently in the object is changed.

See Also

Upper, Lower

Chars

Chars(Long pEncoding=-1, <String pStr>)

Description

Returns the number of characters in the string (not the number of bytes.) Works for ANSI, Utf-8 and Utf-16 encodings

Parameters
Parameter Description
pEncodingPossible values are st:EncodingANSI, st:EncodingUft8st:EncodingUtf16. If omitted then the current value in the st.Encoding property is used
pStrThe string to count the characters for. If omitted then the current value of the object is used.
Return Value

The number of characters in the string

See Also

ToAnsi , ToUnicode , Length
 

CleanFileName

CleanFileName (<string fileName>, <string replaceChar>)

Description

Returns a string which contains a cleaned version of the passed file name, with any invalid characters removed.
The filename should not include the path as the \ character is included in the list of characters which is cleaned.

Parameters
Parameter Description
fileNameThe file name to create a clean version of. If omitted then the current value is used.
replaceCharOptional parameter for the replacement character. Defaults to an underscore.

Return Value


Returns a string which contains a cleaned version of the passed file name, with any invalid characters removed. If the pFileName parameter was omitted then the current value is updated. If the filename parameter is passed, then the current value is not updated.

See Also

FileNameOnly, ExtensionOnly, PathOnly, ClipLength, Trim, Squeeze

Clip

Clip ()

Description

Clips the string (removes trailing white space).

Parameters

None

Return Value

None

See Also

ClipLength, Trim, Squeeze

ClipLength

ClipLength ()

Description

Returns the length of the current string, ignoring any trailing spaces.
See the Length method for returning the length of the string including trailing spaces.

Parameters

None

Return Value

Returns the length clipped length of the current string (the length minus trailing spaces).

See Also

Length

ColorToHex

ColorToHex (long claColor, bool addHash=false)

Converts a Clarion BGR color stored in a long to a string that contains the hexadecimal representation of the color. The hexadecimal string is made up of six characters (and is optionally prefixed by a hash character if addHash is passed as true).

If the clacolor parameter contains a clarion color equate (COLOR:SCROLLBAR through COLOR:MENUBAR) then the current system color is fetched and that color is returned as a fixed hex value.

Parameters
Parameter Description
claColorA long that contains the color to convert
addhash [optional]If this is set to True then the hexadecimal string starts with a hash. Primarily for compatibility with web (HTML, CSS etc.) colors. For example 0 (black) would produce '#000000'
Return Value

Returns a string that contains the string hexadecimal representation of the color. The current contents of the string are not altered.

Example
Example
col  long
hCol string(7)
St   StringTheory
  code
  col = color:red
  hCol = St.ColorToHex(col)
! hCol contains 'FF0000'
  hCol = St.ColorToHex(col, true) ! hCol contains '#FF0000'
See Also

ColorFromHex

ColorFromHex

ColorFromHex  (string hexColor)

Description

Converts a string that contains the hexadecimal representation of a color to a long that contains a standard Clarion BGR color. The hexadecimal string is made up of six or three characters and may be prefixed by a hash character.

Parameters
Parameter Description
hexColorA string that contains the hexadecimal color.
Can be upper or lower case and can have a hash character as a prefix (HTML/CSS style).
Examples include ABCDEF, FFF, #ABC, #123456
Return Value

Returns a long that contains the Clarion BGR color. The current value of the string is not altered.

Example
Example
col long
hCol string(7)
St StringTheory
  code
  hCol = 'ff0000'
  col = St.ColorFromHex(hCol)
  hCol = '#eeeeee'
  col = St.ColorFromHex(hCol)
See Also

ColorToHex

ContainsA

ContainsA (String Alphabet, [String TestString], [Long pClip])

Description

Returns True if the string contains at least one character from the passed alphabet.

Parameters

Parameter Description
AlphabetA list of individual characters. If the string contains any of the characters in this list, then true is returned.
TestString (optional)The string to test. If omitted the current string value of the object is used.
Clip (Optional)If true (the default) then the alphabet string is clipped when doing the text. If you want to test for a space, and the space is not the last character, then you can leave this as true. In the case where you are testing only for spaces then use .ContainsA(' ', ,false)

Return Value

Returns True (1) if the string contains at least one character from the passed alphabet and False (0) otherwise.

See Also

IsAllDigits, ContainsADigit, IsAll

ContainsADigit

ContainsADigit ()

Description

Returns True if the string contains at least one digit character ('0' to '9'). This method is equivalent to calling
self.ContainsA('0123456789')

Parameters

None

Return Value

Returns True (1) if the string contains at least one digit character ('0' to '9'), and False (0) otherwise.

See Also

IsAllDigits, ContainsA

Count

Count (string searchValue, long pStep=1, long pStart=1, long pEnd=0, long noCase=0, bool softClip = true, Overlap = true)

Description

Returns the number of times that the searchValue appears in the current string. The search area can be limited using pStart and pEnd. If omitted, or zero, the whole string is used.

For case insensitive matches set the noCase parameter to true (the default value is false for case sensitive matching). By default the method will return a count of all matching strings that start within the passed range, even if the string overlaps the passed pEnd parameter. To include on strings that are completely within the pStart to pEnd range the softClip parameter can be passed as False.

This method does not alter the current string.

Parameters

Parameter Description
searchValueThe value to search the string for.
pStep [optional]The number of characters to step through the string for each search. This parameters is optional and defaults to 1.
pStart [optional]Position in the string to start the search at. Defaults to 1 (the start of the string).
pEnd [optional]Position in the string to end searching at. This parameter is optional, the default of 0 searches to the end of the string.
noCase [optional] If this is set to non zero then the search is case insensitive, otherwise a case sensitive search is done (the default behaviour).
softClip [optional]By default (with softClip set to True) the method will return a count of all matching strings that start within the passed range, even if the string overlaps the passed pEnd parameter. To include on strings that are completely within the pStart to pEnd range the softClip parameter can be passed as False.
Overlap [optional]If true then the test is moved forward 1 character when a match is found. If false then the test is moved forward by the length of the substring when a match is found. For example, if overlap is true then AA is found 3 times in AAAA. If it is false then it's found twice in AAAA.
Return Value

Returns the number of times that the searchValue string is found within the current string. Returns zero if no occurrences are found.

Examples

Example
st.SetValue('abcabcabc')
Message('Count all instances: ' & st.Count('abc'))                      ! Returns 3
Message('Count with start and end: ' & st.Count('abc', 1, 1, 8))        ! Returns 3
Message('Count with softClip=false: ' & st.Count('abc', 1, 1, 8, False, False)) ! Returns 2 with softClip=false
See Also

CountWords, WordStart, WordEnd, Instring, Replace

CountWords

CountWords (long startPos = 1, long TextType = ST:Text, <String pCharList>)

Description

Returns the number of words in the string

Parameters
Parameter Description
Long startPos [optional]The start position to begin counting words from. Defaults to the start of the string
Long TextType [optional]Defaults to ST:TEXT (0) (the string is assumed to be normal text).

If set to ST:HTML (1) the string is assumed to be HTML encoded, so escape sequences such as '&nbsp;' and other encoded characters are not treated as words.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character.)
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?()*/+=<>:' when the TextType parameter is set to ST:HTML. (no & char)
Return Value

The number of words in the string, or zero if string is empty, contains no words, or the passed parameters are invalid.

See Also

WordStart, WordEnd

Crop

Crop (<long start>, <long end>)

Description

Sets the string to be a subset of itself. The portions of the original string outside the crop are discarded. This is equivalent to calling Slice() to extract a substring and then setting the value of the StringTheory object to the slice. For example, if the current string contains '123456789' and Crop(4,7) is called then the current string will contain '4567'. The start and end parameters are optional and default to the start (first character) and end (last character) of the string respectively. Crop is inclusive and will include the start and end positions.

Parameters
Parameter Description
startThe position to start the crop at (the first character to be included in the cropped string). If the start parameter is omitted then it defaults to the start of the string (the string will only be cropped at the end).
endThe position to end the crop at (the last character to be included in the cropped string). If the end parameter is omitted then it defaults to the end of the string (the string will only be cropped at the front).
Return Value

None. The contents of the object are changed.

Example
Example
st StringTheory
  code
  st.SetValue('123456789')
  st.Crop(4, 7)
! Crop the string from the forth to the seventh characters
   Messsage(st.GetValue())
! Will display: 4567
See Also

Slice, Sub, SetLength, Split, Trim, Left, Clip

DecEntityToChar

DecEntityToChar()

Description

Converts any text in the string of the form &#nnn; to the actual character. If the string is in ANSI mode then ErrorTrap will be called for any characters greater than 255.

EndsWith

EndsWith (String Sub, <long Case>, <Long pClip>)

Description

Checks to see if the current object ends with a particular sub string.

Parameters
Parameter Description
SubThe sub string to check for. If this string is empty then the method returns true.
CaseSet this to false if the test is case insensitive. The default value is true, meaning the test is case sensitive.
ClipIf this is true (the default) then the Sub string is clipped before comparing to the stored string. If set to false then any trailing spaces in the Sub parameter will need to match trailing spaces in the string.
Return Value

True if there is a match, or the Sub parameter is empty or False if there isn't a match.

Example
Example
st     StringTheory
  code
  st.SetValue('123456789')
  x = st.EndsWith('89')    ! x is true at this point
  x = st.EndsWith('')      ! x is true at this point
  x = st.EndsWith('8')     ! x is false at this point
See Also

StartsWith

Equals

Equals (StringTheory pOtherValue,  Long pOptions=ST:SimpleCompare)
Equals (String pOtherValue, Long pOptions=ST:SimpleCompare + ST:Clip)


Description

Checks to see if the contents of the StringTheory object match another StringTheory object.
A fixed text (ANSI) value may be used in place of another StringTheory object.
This method can do a simple comparison, or compare ANSI, utf-8 and utf-16 strings with each other.

Parameters
Parameter Description
pOtherValueThe StringTheory object, or string,  to compare this object to.
If this parameter is a string then the string is assumed to be ANSI, and the default option includes clipping.
pOptions
(optional)
Contains flags describing the depth of the comparison.
ST:Clip : Only when a String form is used - clips the string before comparing
ST:SimpleCompare : The strings are compared byte for byte regardless of encoding.
ST:UnicodeCompare : The strings are first converted to a common type before comparing them. The original strings are not altered.
Return Value

True if the objects match.

See Also

ErrorTrap

ErrorTrap (string MethodName, string Message)

Description

This method is called when there is an error raised in the Load or Save methods. If the LogErrors property is set to true then the error message will be passed on to the Trace method. This is an ideal method to use to add custom error handling to the LoadFile and SaveFile methods.

EncodedWordDecode

EncodedWordDecode()

Description

Encoded-Word encoding is used by mail clients when special characters are required in the header fields (like the Subject). This method converts the current string (which is in Encoded-Word format) to be a normal ANSI string.

The form of the text is is
=?charset?encoding?encoded?text?=

The charset may be any character set registered with IANA. Typically it would be the same charset as the message body. The encoding can be either "Q" denoting Q-encoding that is similar to the quoted-printable encoding, or "B" denoting base64 encoding.
Encoded text is the Q-encoded or base64-encoded text.

An encoded-word may not be more than 75 characters long, including charset, encoding, encoded text, and delimiters. If it is desirable to encode more text than will fit in an encoded-word of 75 characters, multiple encoded-words (separated by CRLF SPACE) may be used.

See also

EncodedWordEncode, Base64Encode, Base64Decode, URLEncode, URLDecode

EncodedWordEncode

EncodedWordEncode([String Charset], [Long Encoding=st:QuotedPrintable])

Description

Encoded-Word encoding is used by mail clients when special characters are required in the header fields (like the Subject). This method encodes the current string into encoded word format.

An encoded-word may not be more than 75 characters long, including charset, encoding, encoded text, and delimiters. If it is desirable to encode more text than will fit in an encoded-word of 75 characters, multiple encoded-words (separated by CRLF SPACE) may be used.

Parameters

Parameter Description
Charset - optionalThe Charset to use. The charset may be any character set registered with IANA. For example iso-8859-1. If omitted then the ASCII charset (iso-8859-1) will be used.
Encoding - optionalOne of st:QuotedPrintable or st:Base64. If the parameter is omitted, or invalid then st:QuotedPrintable  is used.

Returns

Nothing

See also

EncodedWordDecode, Base64Encode, Base64Decode, URLEncode, URLDecode

ExtensionOnly

ExtensionOnly ([String FileName])

Description

Returns just the extension part of the filename, ie the part after the last period character. If there is no period in the string then the method returns a blank string. If the FileName parameter is omitted, then the current string value is used.

Parameters
Parameter Description
FileNameIf a Filename is passed into the method, then the Extension of that filename is returned. If the parameter is not passed then the contents of the string is treated as a filename, and the extension of that is returned.

Returns


The extension part of the filename, not including the period. The current string value is not altered by this method.

See also

PathOnly , FileNameOnly , CleanFileName

FileNameOnly

FileNameOnly ([String FileName],Long IncludeExtension=true)

Description

If the passed string contains a fully qualified filename, ie a filename including the path, then this method strips off the path part, and returns just the filename part (including the extension).  If the FileName parameter is omitted, then the current string value is used.

Parameters
Parameter Description
FileNameIf a Filename is passed into the method, then the Extension of that filename is returned. If the parameter is not passed then the contents of the string is treated as a filename, and the extension of that is returned.
IncludeExtension (optional)If omitted, or True, then the filename returned will include the extension part of the name. If the parameter is set to False then the name without the extension is returned.

Returns


The filename (not including the period) or the filename and extension (with a period separator) depending on the value of the IncludeExtension parameter. . The current string value is not altered by this method.

Example
Example
st   stringtheory
s    string(255)
  code
  s = command(0)
  s = st.FileNameOnly(s)

See also


PathOnly , ExtensionOnly , CleanFileName

FindBetween

FindBetween (string Left, string Right, *long Start, *long End, bool NoCase=0, long Exclusive=1)

Description

Return the part of the string between two search strings (exclusively, i.e. the Left and Right delimiter are not included in the returned string). Also sets the passed Start and End to the position in the string that the returned string was found at, which allows for repeated calls to FindBetween to find multiple substrings using the same delimiters.

Parameters
Parameter Description
LeftThe left hand delimiter. If this is blank then the start of the string is used.
RightThe right hand delimiter. If this is blank then the end of the string is used.
StartThe search for the delimiter starts at this position in the string. If less than or equal to zero this defaults to the start of the string. When the method returns this is set to the start position of the returned string.
EndThe search ends at this position in the string (delimiters after this are ignored). Defaults to the length (end) of the string if the passed value is less than or equal to zero. On return this is set to the end position of the returned string.
NoCase [optional]If this is set then the delimiter search is case insensitive, otherwise it is case sensitive.
Exclusive [optional]If this is set to true (the default) then the delimiters are not included in the returned string. If it is set to false then they are included in the returned string.
Return Value

Returns the string between the passed delimiters if it is found, otherwise a blank string is returned.

Example

Find all strings between the start and end delimiters: '[[' and ']]'
Example
pStart        long
pEnd          long
  code
    loop
        betweenVal = st.FindBetween('[[', ']]', pStart, pEnd)
        if betweenVal = ''
            break
        else
            ! do something with the returned value
        end

        ! Reset pEnd to allow the next iteration to search
        ! to the end of the string, and set the new start
        ! position to the end of the previously found string.
        pStart = pEnd
        pEnd = 0
    end
See also

Between

FindWord

FindWord (long WordNumber, long startPos = 1, long TextType=ST:Text, *Long Start, *Long End, <String pCharList>)

Description

Returns a string that contains the word at the passed position.

Parameters
Parameter Description
long WordNumberThe number (position) of the word in the string to return. For example given the string "Hello World", a WordNumber of 2 would return "World".
long startPos [optional]The position to start searching for the word at.
long TextType [optional]Defaults to ST:TEXT (0) (the string is assumed to be normal text).

If set to ST:HTML (1) the string is assumed to be HTML encoded, so escape sequences such as '&nbsp;' and other encoded characters are not treated as words.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character.)
StartA long which will be populated with the position of the first character of the word in the string
EndA long which will be populated with the position of the last character of the word in the string
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:HTML.
Return Value

Returns a string that contains the word at the specified position if successful, or an empty string otherwise (if the passed position is invalid or doesn't exist). The Start and End parameters are set to the position of the located word, or 0 otherwise.

See also

GetWord

FormatMessage

FormatMessage (long Error)

Description

This method converts the Windows Error Code into a Text description of the error.
See also ErrorTrap method, and WinErrorCode property.

Free

Free (long Lines=false, Long Force=false)

Description

A method used to clear the string free the memory used by the object.

Parameters

Parameter Description
LinesIf set to True then FreeLines is also called. If set to false (the default) then the Lines queue is unaltered.
ForceIf set to false (the default) then existing memory owned by the object is not disposed. In other words the string is cleared, but the memory is held. If set to true then the memory is disposed.

FindChar

FindChar (string pSearchValue, long pStart=1, long pEnd=0, [String pText])

Description

A fast brute force single character search. Faster than the standard Instring for some cases.

Parameters
Parameter Description
pSearchValueThe character to search for.
pStart [optional]The position to start searching at. Defaults to the start of the string.
pEnd [optional]The position to end searching. Defaults to the end of the string.
pText [optional]The string to search. If omitted the object value is searched.
Return Value

Returns the position that the character was found at, or zero if was not found.

FindChars

FindChars (string pSearchValue, long pStart=1, long pEnd=0, <String pText>)

Description

A fast brute force string search. Faster than the standard Instring for some cases.

Parameters
Parameter Description
pSearchValueThe substring to search for.
pStart [optional]The position to start searching at. Defaults to the start of the string.
pEnd [optional]The position to end searching. Defaults to the end of the string.
pText [optional]The string to search.
Return Value

Returns the position that the substring was found at, or zero if not found.

FromBlob

FromBlob (*blob blobField)

Description

Load the value from a BLOB into the StringTheory object

Parameters
Parameter Description
*blob blobFieldThe BLOB to retrieve the data from.
Return Value

Returns true (1) for success and zero for failure

Examples
Example
s               StringTheory
blobContents    string
  code
 
  s.FromBlob(MailData.Text)     ! Store the data
    blobContents = s.GetValue()   ! Get the stored data

FromBytes

FromBytes (*string pSrc, *byte pDest, long pOffset=1),
FromBytes (*string pSrc, *short pDest, long pOffset=1)
FromBytes (*string pSrc, *ushort pDest, long pOffset=1)
FromBytes (*string pSrc, *long pDest, long pOffset=1)
FromBytes (*string pSrc, *ulong pDest, long pOffset=1)
FromBytes (*string pSrc, *sreal pDest, long pOffset=1)
FromBytes (*string pSrc, *real pDest, long pOffset=1)
FromBytes (*string pSrc, *decimal pDest, long pOffset=1)
FromBytes (*string pSrc, *cstring pDest, long pOffset=1)
FromBytes (*string pSrc, *pstring pDest, long pOffset=1)
FromBytes (*string pSrc, *string pDest, long pOffset=1)

Description

Retrieves the binary value from the pSrc string parameter (at the position indicated by pOffset) and stores it in the passed second parameter variable. The actual bytes are moved from the string to the destination value. 
The final three forms of the method is a simple move from one string to another.

The opposite of the FromBytes method is the ToBytes method.

FromBytes and ToBytes to not use, or alter, the current contents of the StringTheory object. For an equivalent pair of methods that work on the object itself see GetBytes and SetBytes.

Parameters
Parameter Description
PSrcA string that contains the binary value to be retrieved.
pValThe variable to store the binary value into
pOffsetThe offset index into the string for where to get the value from. If omitted then then the default position is the first character in the string.

Example


Example
a   Long
s   String(10)
  code
  s = 'AAAABBBB'
  str.FromBytes(s,a)
 
! a = 1094795585 = 041414141h

  str.FromBytes(s,a,5)
 
! a = 1111638594 = 042424242h

Return Value


None

See Also

ToBytes  , GetBytes , SetBytes

GetBytes

GetBytes (*byte pDest, long pOffset=1),
GetBytes (*short pDest, long pOffset=1)
GetBytes (*ushort pDest, long pOffset=1)
GetBytes (*long pDest, long pOffset=1)
GetBytes (*ulong pDest, long pOffset=1)
GetBytes (*sreal pDest, long pOffset=1)
GetBytes (*real pDest, long pOffset=1)
GetBytes (*decimal pDest, long pOffset=1)
GetBytes (*cstring pDest, long pOffset=1)
GetBytes (*string pDest, long pOffset=1)
GetBytes (*pstring pDest, long pOffset=1)


Description

Retrieves the binary value of bytes from the StringTheory object and stores it in the Destination variable. This method is used in combination with SetBytes to store and retrieve binary values without any transformation.

Parameters
Parameter Description
pDestThe variable to receive the value from the StringTheory object.
pOffsetThe offset in the Object string to get the value from.

Return Value


None.

See Also

SetBytes , ToBytes, FromBytes

GetBytes

GetBytes (*? pVal, string pType), bool

Description

Retrieves the binary value from the StringTheory object and stores it in the passed variable. This method is used in combination with SetBytes to store and retrieve binary values without any transformation. This wrapper method allows any type to be passed along with the Clarion TYPE for the variable passed ('STRING', 'LONG', 'REAL' etc.)

Parameters
Parameter Description
pValThe variable to receive the value stored in the StringTheory object
pTypeA string that contains the Clarion type for the passed parameter: 'BYTE', 'SHORT', 'USHORT', 'LONG', 'ULONG', 'REAL' etc.

Return Value


Returns True if successful, or False if an error occurs (an unsupported data type, incorrect length, no data stored etc.)

See Also

SetBytes, ToBytes, FromBytes

GetValue

GetValue ()

Description

Returns the value of the string currently stored in the object.

See also

SetValue , GetValuePtr

GetValuePtr

GetValuePtr()

Description

Returns a pointer to the value of the string currently stored in the object. Use this rather than the value property directly.

See also

GetValue

GetWord

GetWord(long WordNumber, long startPos = 1, long textType=ST:TEXT, <String pCharlist>)

Description

Returns a string that contains the word at the passed position.

Parameters
Parameter Description
long WordNumberThe number (position) of the word in the string to return. For example given the string "Hello World", a WordNumber of 2 would return "World". If the word number is negative, then the search counts words from the end of the string. For example, given the string "This is the end" a word number of -2 would return "the".
long startPos [optional]The position to start searching for the word at.
long TextType  [optional]Defaults to ST:TEXT (0) (the string is assumed to be normal text).

If set to ST:HTML (1) the string is assumed to be HTML encoded, so escape sequences such as '&nbsp;' and other encoded characters are not treated as words.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character.)
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:HTML.
Return Value

Returns a string that contains the word at the specified position if successful, or an empty string otherwise (if the passed position is invalid or doesn't exist).

See Also

FindWord, WordStart, WordEnd, CountWords

Gunzip

Gunzip ()

Description

This function decompresses a string that has been compressed using GZIP (either the external GZIP utility, or the Gzip method.)

Note that this method requires that the ZLIBWAPI.DLL is shipped with your application. You can find this DLL in your \clarion\accessory\bin folder.

Example

If you have a file stored on the disk it can be loaded using the LoadFile method, then unzipped using the Gunzip method.
Example
str.LoadFile('whatever.txt.gz')
str.gzipped = 1
str.Gunzip()
str.SaveFile('whatever.txt')
Return Value

The method will only decompress the string if the gzipped property is set to True. If it is set to False then the function returns st:Z_OK, and the contents of the string are unchanged.

If the decompression fails for some reason, the function will return an error code. The original contents of the string will not be changed. Possible Error codes are;
st:Z_ERRNO             Equate(-1)
st:Z_STREAM_ERROR      Equate(-2)
st:Z_DATA_ERROR        Equate(-3)
st:Z_MEM_ERROR         Equate(-4)
st:Z_BUF_ERROR         Equate(-5)
st:Z_VERSION_ERROR     Equate(-6)
st:Z_NORAM_ERROR       Equate(-98)
st:Z_DLL_ERROR         Equate(-99)

If the decompression is successful then the method returns st:Z_OK, and the gzipped property is set to False.

See Also

Gzip

Gzip

Gzip (long pLevel=5)

Description

This method compressed the current string using the GZIP format. this is the same as using the GZIP.EXE utility to create a .gz file, but the result of the compression remains in the string, not on disk.

If the string is already compressed (i.e. the gzipped property is set to 1) then the function returns without changing the string.

Note that this method requires that the ZLIBWAPI.DLL is shipped with your application. You can find this DLL in your \clarion\accessory\bin folder.

Parameters
Parameter Description
long pLevelThis is a value from 0 to 9 where 1 is the fastest, and 9 is the most compressed. If set to 0 no compression takes place. If omitted the default value for this parameter is 5.

Example


If you have a file stored on the disk it can be loaded using the LoadFile method, then zipped using the Gzip method.
Example
str.LoadFile('whatever.txt')
str.Gzip()
str.SaveFile('whatever.txt.gz')

Return Value


The method will only compress the string if the gzipped property is set to False. If it is set to True then the function returns st:Z_OK, and the contents of the string are unchanged.

If the compression fails for some reason, the function will return an error code. The original contents of the string will not be changed. Possible Error codes are;
st:Z_ERRNO             Equate(-1)
st:Z_STREAM_ERROR      Equate(-2)
st:Z_DATA_ERROR        Equate(-3)
st:Z_MEM_ERROR         Equate(-4)
st:Z_BUF_ERROR         Equate(-5)
st:Z_VERSION_ERROR     Equate(-6)
st:Z_NORAM_ERROR       Equate(-98)
st:Z_DLL_ERROR         Equate(-99)

If the compression is successful then the method returns st:Z_OK, and the gzipped property is set to True.

See Also

Gunzip

HtmlEntityToDec

HtmlEntityToDec()

Description

In HTML, non-ASCII characters can be encoded using a "special name", known as an HTML Entity. For example the familiar copyright symbol,©, can be written in html as &copy; . Ideally this should be represented though in a unicode format as &#169; which is a more generic encoding and "more compatible" with things other than HTML.

This method finds a range of entities in the string, and replaces them with the more standard unicode encoding.

Return Value


None. The current string is altered by this method.

Insert

Insert (long Start, string insertValue)

Description

Inserts the passed string into the stored string at the specified position. The stored string is expanded as needed.

Parameters
Parameter Description
StartStart position to insert at. If the Start parameter is less than or equal to 1, then the new value is prepended to the front of the string. If it is higher than the current length of the string then the current string is padded with spaces so that the new value can be added at the specified position.
insertValueThe string to insert at the specified position. This value is not clipped, so clip if necessary.

Return Value


None

Examples
Example
st.Insert(st.Length()-2, '-NewValue-')

Instring

Instring (string SearchValue,[Long Step],[Long Start],[Long End],[Long NoCase],[Long WholeWord])

Description

Similar to the Clarion INSTRING function, this is used to locate a substring in a string. Some additional parameters, and one behavioral change, make it somewhat more useful though.

Parameters
Parameter Description
SearchValueThe sub string value to look for.
StepThe number of characters stepped in the current value, if a match is not made. Unlike the Clarion INSTRING function (which defaults to the length of the sub string), this value defaults to 1 if omitted.
This number can be < 0. If <0 then the search is performed backwards from the End to the Start. Note that even if this value < 0 then Start remains the "left" position in the string to search, Start and End do not switch place in the parameter list.
StartThe position in the current value to begin searching from. If this parameter is omitted then the search starts at the beginning of the current value.
EndThe position in the current value to stop searching. If this parameter is omitted then the search ends at the end of the current value.
NoCaseIf set to not zero then the search is case insensitive. If this parameter is omitted (or 0) then the search is case sensitive.
WholeWordIf this parameter is set to not zero, then only sub strings which form a Whole Word will be returned. A whole word is defined as any sequence not immediately followed, or preceded by an alpha-numeric character (A through Z, a through z and 0 through 9).
Return Value

The position of the substring in the value, if it is found. If no match is found then 0 is returned. Note that if the Step parameter is set then the Step number, not the Position number of the located string is returned.

Special note: Unlike the Clarion INSTRING command, the default value of Step is 1, not the length of the Search value.

Special note: The Clarion Instring command returns the "step number" (not the position) of the located text when the STEP parameter > 1. The StringTheory version ALWAYS returns the POSITION regardless of the value in STEP.

IsAll

IsAll (String Alphabet, <String TestString>, Long Clip=true)

Description

Returns True if the string contains only characters in the passed alphabet.

Parameters
Parameter Description
AlphabetThe list of characters to test against the string.
TestStringThe string to test. If omitted the current string value of the object is used.
ClipIf true (the default) then the Alphabet is clipped before being used in the test. If you do want to include a space character in the alphabet then make sure it's either not the last character, or this parameter is set to false.
Return Value

Returns True (1) if the string only contains characters from the alphabet, or False (0) otherwise.

Example

st  StringTheory
  code
  st.SetValue(somestring)
  If st.IsAll('ABCDEF0123456789')
    ! contains a hex number
  End


See Also

ContainsADigit, ContainsA, IsAllDigits

IsAllDigits

IsAllDigits ()

Description

Returns True if the string only contains digit characters ('0' to '9'). this is the equivalent of calling
self.IsAll('01233456789')

Parameters

None

Return Value

Returns True (1) if the string contains only digit characters ('0' to '9'), or False (0) otherwise.

Example

st StringTheory
  Code
  st.SetValue(somestring)
  If st.IsAllDigits()
    ! only contains digits
  End


See Also


ContainsADigit, ContainsA, IsAll

IsTime

IsTime ([string Value])

Description

Returns True if the string appears to contain a human-readable time.
Note that this method does not detect a lot of values that would be acceptable to the DeformatTime method. That method assumes the value IS a time, and so is not considering that it might just be a number. This method narrows the pattern considerably.
Parameters
Parameter Description
Value (optional)If a value is passed to the method, then it will do the detection on this value. If not, the contents of the object value will be tested.
Return Value

Returns True (1) if the string appears to contain a Time or False (0) otherwise.

See Also

FormatTime,DeformatTime

JsonDecode

JsonDecode()

Description

Decodes a string that has previously been encoded into the JSON format.

Return Value

Nothing. The current string is altered by this method.

See Also

JsonEncode

JsonEncode

JsonEncode(Long pOptions=0)

Description

Encodes a string so it is a valid JSON string. This treats the \ character as an "escape" character and then followed by a short list of characters that need to be modified.

Parameters
Parameter Description
Options (optional)Default is none.
If set to st:xml then the < character is encoded as \u003c.  This allows the JSON string to be included in XML without creating an unexpected opening tag.

Return Value


Nothing. The current string is altered by this method.

See Also

JsonDecode

KeepChars

KeepChars(string Alphabet)

Description

Removes any characters from the string which are not included in the Alphabet parameter.
 
Parameters
Parameter Description
AlphabetOnly characters specified in this string will be preserved.
Return Value

Returns the number of characters removed from the string. The text in the object is changed.

See Also

RemoveChars

Left

Left ([Long Length],[Long What],[String Pad])

Description

Returns the contents of the string, with leading characters removed. If the length parameter is used then the returned value is either padded with characters, or cropped, so it is exactly the specified length.
Note that this method does not affect the actual stored string. To set the string use the SetLeft method.

Parameters

Parameter Description
Length
(optional)
The Length of the string to return. If omitted, or zero, the current length of the string is used.
If the Length is set to less than the current string length then the string is cropped to fit.
What (optional)Determines what leading characters are removed. Possible options for this parameter are;
st:Spaces (This is the default value if the parameter is omitted.)
st:Tabs
st:cr
st:lf
st:zeros

These options can be added together. For example to remove leading spaces and leading tabs you can use
st.left( ,st:spaces + st:tabs)
To remove all leading spaces, tabs, carriage returns and linefeeds use
st.left( ,st:spaces + st:tabs + st:cr + st:lf)
Pad (optional)Allows you to specify the character to use as the padding character if the length required is greater than the current string. If omitted then the default pad character is a space.

Return Value

Returns the left-justified string.

See Also

Right, SetLeft, SetRight,

Length

Length ()

Description

Returns the current length of the string currently stored in the object.

Note:In Clarion 5.5 the Length keyword is reserved, so in Clarion 5.5, for this method, use the method name LengthA instead.

Parameters

None

Return Value

Returns the length (in byte) of the stored string, or zero if nothing is being stored.

LineEndings

LineEndings (Long Endings = st:Windows)

Description

Converts any ASCII line endings between Windows (CR/LF), MAC (CR) and UNIX (LF) formats. This can be useful for files downloaded from an FTP server that modifies the line endings in text files.

Parameters

Parameter Description
Endings
(optional)
The format desired for the text. Valid options are st:Windows, st:Mac and st:Unix. If this parameter is omitted then st:Windows is used.

Return Value

Returns nothing. The contents of the object are altered to the preferred line ending.

Loadfile

Loadfile (String FileName, Long Offset=0, Long Length=0, Long RemoveBOM=false)

Description

Loads a file off the disk, and places it in the current string value. The maximum size of the file is limited only by the maximum size of a string in Clarion (which is a around two gigabytes.) The existing contents of the object are discarded before the file is loaded.

Parameters
Parameter Description
FileNameThe name of the file to load from disk.
Offset [optional]The offset into the file to begin reading. For example if this is set to 10, then the read will commence with the 11th character. If the value is larger than the file then Errortrap is called, and the current value in the object is cleared. If this value is less than zero, then the read is measured from the end of the file. For example, if this value is -10 then the last 10 characters in the file will be read.
Length [optional]The maximum number of bytes to load. If this number is greater than the data (left) in the file then the available data is read.
RemoveBOM [optional]Default value is false. If set to true, and the file contains a Byte-Order-Mark (BOM) as the first 2 or 3 bytes, then the BOM will be removed when the file is loaded. Regardless of whether this parameter is true or false, the .encoding property will be set if a BOM exists.
Return Value

Returns True (1) for success, or False (0) for failure. If an error occurs the ErrorTrap method is called with additional error information. The number of bytes actually read is available in the bytes property. If the load is successful then the object will contain the file, if it unsuccessful then the object will be empty.

Example
Example
st  stringtheory
  code
    if not st.LoadFile('c:\windows\win.ini')
        Message('An error occured loading the file')
    end
See Also

SaveFile , SetEncodingFromBOM, ErrorTrap

Lower

Lower ([String Quote],[String QuoteEnd])

Converts all the characters (except the ones in quotes) in the current string to lower case.

Parameters
Parameter Description
Quote (optional)A character to identify the start of Quoted Text. Quoted Text will not be lowered by this method. If this parameter is omitted then all the text in the string is lowered.
QuoteEnd (optional)The character to use as the end of Quoted Text. If omitted, and the Quote parameter is not omitted, then the same quote character will be used to delineate the start and end of text.
Example
Example
st stringtheory
  code
  st.SetValue('This is a "TEST" of the LOWER method')
  st.lower('"')
! st now contains 'this is a "TEST" of the lower method'

Return Value


Returns nothing. The contents of the string are changed.

See Also

Upper , Capitalize

MakeGuid

MakeGuid (long pLength=16, long pFlags=st:Upper+st:Number)

Same as Random but with different default parameters. This method makes it simpler to call a method where the default parameters are configures to provide a random string which is suitable for a database unique identifier.

MatchBrackets

MatchBrackets (String pLeftBracket, String pRightBracket, Long pStart=1)

Finds the matching end bracket of a given start bracket.

Parameters
Parameter Description
LeftBracketA single character, indicating the left bracket of the search. For example, ( or < or { and so on.
RightBracketThe right character indicating the right bracket in the search.
StartThe position to start in the string. The first instance of the LeftBracket after the start marks the beginning of the search. If omitted the search starts at the beginning of the string.
Example
Example
st stringtheory
x  Long
  code
  st.SetValue('(a+b)=((c+d)*4)')
  x = st.MatchBrackets('(',')',7)
! x = 15

Return Value


Returns a LONG indicating the position of the right bracket. If the matching bracket is not found then 0 is returned.  The contents of the string is not changed.

See Also

 

MD5

MD5 (Long pFormat=st:EncHex)

Returns the MD5 hash value of the current string.

Parameters
Parameter Description
pFormat (optional)Determines the format of the result. Possible options are st:EncNone, st:EncHex or st:EncBase64. If omitted this parameter defaults to st:EncHex.

Return Value

A string which contains the MD5 hash of the value in the StringTheory object.

Example
Example 1
st.SetValue(myValue)  ! Store the value to create a hash of
hashVal = st.MD5()    ! ! Get the hex encoded hash from the string
Example 2
st.SetValue(myValue)        ! Store the value to create a hash of
st.SetValue(st.Md5(st:EncBase64)) ! Store the hash in the object
hashString = st.GetValue()  ! Get the base64 encoded hash from the string
Notes

MD5 is no longer considered a safe hash for security purposes. When hashing for security rather use sha-256 (available in Cryptonite.) When used for non-security purposes (for example as an advanced form of crc) then MD5 is still ok.

NOTE: This method is only included if your project has the MD5=>1 project define included (this can be enabled on the global extension by ticking the "Enable MD5" tickbox).

MergeXml

MergeXml (String New, Long Where)

Description

This method allows you to inject a new xml block into an existing xml document, in other words inside the current xml root tag.. The object contains the current XML block, and the contents of the object are changed.

Parameters
Parameter Description
NewThe block of new xml code to inject into the current document.
WhereIndicates the position where the new node must be placed. Valid options are st:First and st:Last
Examples

st    StringTheory
xml   String(255)
  code
  st.SetValue('<docroot><node>Hello</node></docroot>')
  xml = '<anotherNode>World</anotherNode>'


Taking the above as the starting point, the following line

st.MergeXML(xml,st:first)
would result in st containing something like this;

<docroot><anotherNode>World</anothernode><node>Hello</node></docroot>

whereas

st.MergeXML(xml,st:last)

would result in st containing something like this;

<docroot><node>Hello</node><anotherNode>World</anothernode></docroot>

Returns

Nothing

Normalize

Normalize(Form=st:NFKD, PreserveEncoding=true)

Description

Unicode contains multiple possible encodings for the same character, depending on the encoding style. This can cause problems when trying to do string comparisons. Normalizing reduces the strings to the "same" encoding style which makes for easier comparisons.

Normalizing is only applicable to Unicode (utf-8 or utf-16) strings. If this method is called, and the current encoding is ANSI then the method returns without doing anything.

Normalizing is also used to remove ligatures, usually in preparation for conversion to ANSI.  It is invoked automatically by the ToAnsi method.

Parameters
Parameter Description
FormThe string can be normalized to one of four forms. Valid values here are;
st:NFC, st:NFD, st:NFKC and st:NFKD. If omitted defaults to st:NFKD.
Preserve EncodingIf omitted defaults to true. If true then if the string is encoded as utf-8, then it will remain as utf-8 when this method completes. If it is false, and the current encoding is utf-8 then the encoding of the string will change to utf-16.
If the current encoding is ANSI then the method immediately returns without any change to the string (regardless of this parameter setting.)

Returns

Nothing. The current value of the string is possible changed, and the encoding of the string may be changed to utf-16.
 

PathOnly

PathOnly ([String FileName])

Description

If the passed string contains a fully qualified filename, i.e. a filename including the path, then this method strips off the filename part, and returns just the path part. If the FileName parameter is omitted, then the current string value is used.

Parameters
Parameter Description
FileNameIf a Filename is passed into the method, then the Path part of that filename is returned. If the parameter is not passed then the contents of the string is treated as a filename, and the path part of that is returned.

Returns


The path part of the filename. The trailing \ is not included. The current string value is not altered by this method.

Example
Example
st   stringtheory
s    string(255)
  code
    s = command(0)
    s = st.PathOnly(s) 
! c:\program\bob

See also

FileNameOnly , ExtensionOnly , CleanFileName

Prepend

Prepend (String NewValue,<Long pClip>,<String pSep>)

Description

The opposite of the Append method. The passed parameter is added to the front of the current string.

See Also

Append

Quote

Quote (<string pQuotestart>,<string pQuoteEnd>)

Description

Wraps the string in the passed quotation marks.

Parameters
Parameter Description
pQuoteStartOptional character to use as the opening quotation mark. Defaults to a double quote (").
quoteEndOptional character to use as the closing quotation mark. Defaults to a double quote (").
Return Value

None

Example
Example
st.Quote()  ! Wrap the string in double quotes

QuotedPrintableEncode

QuotedPrintableEncode()

Description

This method encodes the current string into QuotedPrintable format. Often used by email systems, this converts all data to a 7 bit format, with a maximum line length of 76 characters. It uses the equals sign (=) as the escape character.

Parameters

None

Returns

Nothing. The current value in the object is changed.

Example
Example
st.SetValue('If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.')
st.QuotedPrintableEncode()

! object now contains
If you believe that truth=3Dbeauty, then surely mathematics is the most bea=
utiful branch of philosophy.
See Also

QuotedPrintableDecode

QuotedPrintableDecode

QuotedPrintableDecode()

Description

This method decodes the current string from QuotedPrintable format. Often used by email systems, this data in in a 7 bit format, with a maximum line length of 76 characters. It uses the equals sign (=) as the escape character.

Parameters

None

Returns

Nothing. The current value in the object is changed.

Example
Example
st.SetValue('If you believe that truth=3Dbeauty, then surely mathematics is the most bea=<13,10>utiful branch of philosophy.')
st.QuotedPrintableDecode()

! object now contains
If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.
See Also

QuotedPrintableEncode

Random

Random ([Long Length], [Long Flags], [String Alphabet])

Description

Fills the string with random characters.
This function is useful when generating random file names, or creating GUID strings or things like that.
Because of the ability to generate only digits it's also useful for generating really large random numbers (in a string).

Parameters
Parameter Description
Length [optional]The length of the random string to return. If omitted the default string length is 16 characters.
Flags [optional]Determines the alphabet that can be used. Can be one or more of the following;
st:Upper - Includes Uppercase letters from A to Z in the alphabet.
st:Lower - Includes lowercase letter from a to z in the alphabet.
st:Number - Includes decimal digits from 0 to 9 in the alphabet
st:Hex - Includes A to F and 0 to 9 in the alphabet. (Only works if st:Upper, st:Lower and st:Number are all excluded from the flags)
st:DNA - Includes the uppercase characters GCAT.
st:AlphaFirst - Regardless of the other bit settings, the first character must be an uppercase letter, A through Z.
Alphabet [optional]In addition to the alphabet created by the Flags settings, add the following specific characters as well. Not that if you want to include a space in your alphabet, and it must not be the last character in the alphabet as this parameter is clipped before usage.
If both the Alphabet and Flags parameters are omitted then the default alphabet is st:Upper.
Returns

The string created. The contents of the string created are also placed in the object value.

Remove

Remove (string pLeft,<string pRight>,long pNoCase=0,long pContentsOnly=0, long pCount=0)

Description

This method allows you to remove a block of text from the string by using a start and end delimiter.

Parameters

Parameter Description
pLeftThe start delimiter of the text to remove. Note that this parameter is not clipped by the method, so you may want to call clip yourself.
pRightThe end delimiter of the text to remove. If this parameter is omitted then the text in pLeft is removed. Note that this parameter is not clipped by the method, so you may want to call clip yourself.
pNoCaseIf set to not zero then the search is case insensitive. If this parameter is omitted (or 0) then the search is case sensitive.
pContentsOnlyOnly the text between the delimiters, not including the delimiters, is removed. The default is false, meaning that the delimiters are removed as well as the contained text.
pCountThe number of occurrences to remove. If set to 0 (the default) then all instances of the text are removed.

Return value

The number of items removed from the string.

Example
Example
htmlString = <td class="tabledata" align="left" ' |
           & 'colspan="2" valign="middle" id="td_11">' |
           & 'Hello World</td>'

st.SetValue(htmlString)
st.Remove('<td','>')
st.Remove('</td>')
Message(st.GetValue())
The output (value stored in the StringTheory object) of the above example is: 'Hello World'

See Also

RemoveAttributes, Replace

RemoveAttributes

RemoveAttributes (String pTag, Long pCount=0)

Description

Finds all instances of <tag> in the string, and removes all attributes from those tags. Designed for making parsing HTML simpler (although XML and any other format that uses tags and attributes is supported), by removing the attributes, but leaving the tags in place. For example for the tag 'td':

'<td class="tabledata" align="left" colspan="2" valign="middle" id="td_11">'

Would become:

'<td>'

Parameters
Parameter Description
pTagThe tag to replace attributes for. This should just be the actual tag name, without any angle brackets or attributes.
pCount (optional)Limits the number of tags to search for, and remove attributes from. If 0, or omitted, then there is no limit.
Return value

None

Examples
Example
htmlString = <td class="tabledata" align="left" ' |
           & 'colspan="2" valign="middle" id="td_11">' |
           & 'Hello World</td>'

st.SetValue(htmlString)
st.RemoveAttributes('td')
Message(st.GetValue())
The output (value stored in the StringTheory object) of the above example is: '<td>Hello World</td>'

RemoveChars

RemoveChars(string Alphabet)

Description

Removes any characters from the string which are specified in the Alphabet parameter.
 
Parameters
Parameter Description
AlphabetAll characters specified in this string will be removed.
Return Value

Returns the number of characters removed from the string. The text in the object is changed.

See Also

KeepChars

RemoveXMLPrefixes

RemoveXMLPrefixes()

Description

Inspects the strings for XML tags of the form <tag> and </tag>. If the tag name contains a prefix then it is removed. For example <ns:tag> becomes <tag>.
 
Return Value

Nothing is returned. The text in the object is changed.

See Also

RemoveAttributes , MergeXML

Replace

Replace (string oldValue, string newValue, [long count=0], [long start=1], [long end=0], [long NoCase=0], [bool Recursive=false])

Description

Searches for instances of Old Value in the current string and replaces them with NewValue.

Parameters
Parameter Description
oldValueThe value to search for.
newValueThe replacement value.
count [optional]If the Count parameter is set, then the method will terminate after Count instances of OldValue have been found, and replaced.
Start [optional]Position to start searching from. Defaults to 1 (the start of the string)
End [optional]Position to stop search the string at. Defaults to 0 (which will search to the end of the string).
NoCase [optional]If the NoCase parameter is true (1) then a case-insensitive search will be done. The default is 0 (case sensitive).
Recursive [optional]If Recursive is set to True then a recursive find and replace is performed (after replacement the new replacement text is searched again in case it contains the text being replaced). This is not frequently used and can reduce performance significantly.
Return value

The number of items replaced in the string.

Examples
Example
! Replace all occurrences of findString with replaceString:
st.SetValue('Frank-Was-Here')
st.replace('-',' ')

! Replace only the first occurrence
st.SetValue('Frank-Was-Here')
st.replace('-',' ',1)

! Replace all. Case insensitive, starting at character 10,
! ending at character 20 in the search string.
st.SetValue('Frank-Was-Here-On-A-Wednesday-Last-Month')
st.replace('-',' ', ,10,20,true)

Reverse

Reverse([String pString])

Description

Reverses the byte order inside a string. So ABCD becomes  DCBA.

Parameters

Parameter Description
pString
(optional)
If a string is passed then the passed string is reversed and returned.
If no string is passed then the current contents of the object are reversed and nothing is returned.

If a parameter is passed then the current value in the object is unaltered.

Return Value

Returns nothing (if no parameter) or the reversed version of the passed parameter.

Example

str  StringTheory
  code
  str.SetValue('ABCD')
  str.Reverse()
 
! str now contains DCBA

Example

str  StringTheory
s    string(10)
  code
  s = str.reverse('ABCD')
  ! s now contains DCBA


 

Right

Right ([Length],Long What = 0,[String Pad])

Description

Returns the contents of the string, with trailing characters removed. If the length parameter is used then the returned value is either padded with spaces at the front, or cropped, so it is exactly the specified length.
Note that this method does not affect the actual stored string. To set the string use the SetRight method.

Parameters

Parameter Description
Length
(optional)
The Length of the string to return. If omitted, or zero, the current length of the string is used.
If the Length is set to less than the current string length then the string is cropped to fit.
What (optional)Determines what trailing characters are removed. Possible options for this parameter are;
st:Spaces (This is the default value if the parameter is omitted.)
st:Tabs
st:cr
st:lf
st:zeros

These options can be added together. For example to remove trailing spaces and trailing tabs you can use
st.Right( ,st:spaces + st:tabs)
To remove all trailing spaces, tabs, carriage returns and linefeeds use
st.Right( ,st:spaces + st:tabs + st:cr + st:lf)
Pad (optional)Allows you to specify the character to use as the padding character if the length required is greater than the current string. If omitted then the default pad character is a space.

Return Value

Returns the right-justified string.

See Also

Left, SetLeft, SetRight

SaveFile

SaveFile (string fileName, <long appendFlag>)
SaveFile (*string newValue, string fileName, long appendFlag, <long dataLen>)


Description

Saves the current string (or a passed string) to the disk as a file, or appends the current string to an existing file on the disk.

If the newValue parameter is used, then the value in that string is saved, rather than the current string.
If the appendFlag parameter is set to true then the string is appended to the current file. If it set to false then the current string is saved, and the current values in the file, if the file already exists, is lost.

Parameters
Parameter Description
fileNameThe name of the file to save to.
newValue [optional]If the second form of the method is called and a newValue is passed, then the newValue string is saved to disk rather than the contents of the StringTheory object.
appendFlag If a non zero value is passed then the file is appended to rather than overwritten. This parameter is optional if the first form is called, but required if the second form is called.
dataLen [optional]The length of the data to write. If omitted or zero then the entire newValue is written.
Return Value

Returns True (1) for success and False (0) for failure. If an error occurs then the ErrorTrap method is called with additional information.

See Also

LoadFile , ErrorTrap

SerializeGroup

SerializeGroup(*Group pGroup,<String pBoundary>, <string pQuotestart>, <string pQuoteEnd>, Long pLevel=1, Long pFree=true)

Description

Serializes a group into a separated string. The separator can be any character, or characters specified in the boundary.

Nested groups can use different separators. For example in EDI applications it's possible to have a comma separated list, where the sub level fields are * separated and those can in turn contain ^ separated fields.

Parameters
Parameter Description
pGroupThe group structure to serialize.
pBoundary
[optional]
The boundary string (one or more characters) which appear between the fields. For example, in a pipe-separated string this would be a | character. If omitted this parameter defaults to a comma (,).

This field can contain multiple boundaries (as an I separated list) so that nested groups in the structure can be separated with a different boundary. For example ',I*I^'.

If this field is a StringTheory object, instead of a string, then the StringTheory object should be pre-split using whatever character for the boundary separator is preferred. In this way I can be used as a separator if desired.
pQuoteStart
[optional]
A start-quote string to surround fields which may contain the boundary character(s). If omitted then no boundary character is used.
pQuoteEnd
[optional]
An end-quote string to surround fields which may contain the boundary character(s). If omitted the start-boundary string is used.
pLevel
[optional]
The separator level to use as the first separator. Default value is 1.
pFree
[optional]
Default value is true. If true, then the current value of the object is cleared before the serialize is done. If false then the serialized group is added to the current value of the object.

Return Value

The number of fields which have been serialized.
The contents of the object are altered.

Examples

Example 1

str StringTheory
Grp Group
a     String(20)
b     Long
c     String(20)
    End

  Code
  grp.a = 'hello'
  grp.b = 100
  grp.c = 'worlds'
  str.serializeGroup(grp)
 
! str now contains hello,100,worlds

Example 2

str StringTheory
EdiGroup Group
a          String(20)
b          Long
c          String(20)
SubGroup1  Group
d            String(5)
e            String(5)
SubGroup2    Group
f              Long
g              String(10)
             End
           End
h          String(10)
         End

  CODE
  EdiGroup.a = 'here'
  EdiGroup.b = 10
  EdiGroup.c = 'there'
  EdiGroup.SubGroup1.d = 'went'
  EdiGroup.SubGroup1.e = 'the'
  EdiGroup.SubGroup1.SubGroup2.f = 99
  EdiGroup.SubGroup1.SubGroup2.g = 'rabbit'
  EdiGroup.h = 'pie'
  str.SerializeGroup(EdiGroup,',I*I^')
 
! str now contains here,10,there,went*the*99^rabbit,pie

See Also

SerializeQueue

SerializeQueue

SerializeQueue(*Queue pQueue, String pRecordBoundary, String pFieldBoundary, <String pQuotestart>, <String pQuoteEnd>, Long pLevel=1, Long pFree=true)

Description

This method is the same as SerializeGroup except that it serializes a Queue not a Group. An additional parameter (pRecordBoundary) allows you to set the record boundary. If omitted then a CRLF ('<13,10>') is used as the record boundary.

See Also

SerializeGroup

SetBytes

SetBytes (*byte pVal),
SetBytes (*short pVal)
SetBytes (*ushort pVal)
SetBytes (*long pVal)
SetBytes (*ulong pVal)
SetBytes (*sreal pVal)
SetBytes (*real pVal)
SetBytes (*decimal pVal)
SetBytes (*cstring pVal)
SetBytes (*string pVal)
SetBytes (*pstring pVal)


Description

Retrieves the binary value from the StringTheory object and stores it in the passed variable. This method is used in combination with SetBytes to store and retrieve binary values without any transformation - for example when storing an encrypting numeric values.

Parameters
Parameter Description
pValThe variable to store the binary value of in the StringTheory object. The stored string is the same number of bytes as the passed variable, and each byte retains the same value. This is similar to Clarion's Over attribute.
Return Value

None

See Also

SetBytes, ToBytes, FromBytes

SetBytes

SetBytes (*? pVal, string pType), bool

Description

Stores the binary value of passed variable. This method is used in combination with GetBytes to store and retrieve binary values without any transformation - for example when storing an encrypting numeric values. This wrapper method allows any type to be passed along with the Clarion TYPE for the variable passed ('STRING', 'LONG', 'REAL' etc.)

Parameters
Parameter Description
pValA variable to store the binary value of.
pTypeA string that contains the Clarion type for the passed parameter: 'BYTE', 'SHORT', 'USHORT', 'LONG', 'ULONG', 'REAL' etc.
Return Value

Returns True if successful, or False if an error occurs (an unsupported data type, incorrect length, no data stored etc.)

See Also

GetBytes, ToBytes, FromBytes

SetAll

SetAll (long Length=255)

Description

Repeats the current contents of the string until the current string is Length characters long.

Parameters
Parameter Description
LengthThe length of the resultant string.
Return Value

None

SetEncodingFromBOM

SetEncodingFromBOM(Long RemoveBOM=true)

Description

Text files on disk are sometimes stored with two, or three, initial characters which indicate that the file contains unicode characters. These are known as Byte Order Marks. This method looks for, and optionally removes, the Byte Order Mark, and sets the encoding property to utf-8 or utf-16.

This method is called automatically by the LoadFile method but does not remove the BOM in this case (unless specifically set to do so by the call to LoadFile.) To remove the BOM either call Loadfile with an appropriate parameter or just call this method again with no parameters.

Parameters
Parameter Description
RemoveBOM Set to true by default. If this is true then the Byte Order Mark is removed from the front of the string.
Return Value

None. The .Encoding property may be set, and the string object may be changed.

See Also


LoadFile, AddBOM

SetLeft

SetLeft ([Long Length],[Long What],[String Pad])

Description

Changes the contents of the string, removing leading characters. If the length parameter is used the string is either padded with characters at the end, or cropped, so it is exactly the specified length.
Note that this method affects the actual stored string. To get the string without altering it use the Left method.

Parameters

Parameter Description
Length
(optional)
The Length of the string to set. If omitted, or zero, the current length of the string is used.
If the Length is set to less than the current string length then the string is cropped to fit.
What (optional)Determines what leading characters are removed. Possible options for this parameter are;
st:Spaces (This is the default value if the parameter is omitted.)
st:Tabs
st:cr
st:lf
st:zeros

These options can be added together. For example to remove leading spaces and leading tabs you can use
st.SetLeft( ,st:spaces + st:tabs)
To remove all leading spaces, tabs, carriage returns and linefeeds use
st.SetLeft( ,st:spaces + st:tabs + st:cr + st:lf)
Pad (optional)Allows you to specify the character to use as the padding character if the length required is greater than the current string. If omitted then the default pad character is a space.

Return Value

Nothing. The contents of the string are altered.

See Also

Right, Left, SetRight

SetLength

SetLength (long NewLength, Long Force=false)

Description

Sets the space allocated to the string to a specific length. This is mostly for internal use to be used when extra space is required - for example in the base64 encoding method.

This method is not needed when calling SetValue as that adjusts the length of the string automatically.

See also the Length method to get the current length of the string.

Parameters
Parameter Description
newLengthThe new length for the string.
ForceForces the buffer to be exactly this length. If this is off (the default) then the string is set to be this length, but the buffer itself may remain larger.
Return Value

None

Examples
Example
st.SetLength(st.Length() + 20) ! Increase the length by 20 characters

SetRight

SetRight ([Length], Long What=0, [string Pad])

Description

Changes the contents of the string, with trailing characters removed. If the length parameter is used then the string is either padded with some character at the front, or cropped, so it is exactly the specified length.
Note that this method affects the actual stored string. To get the string without altering it use the Right method.

Parameters

Parameter Description
Length
(optional)
The Length of the string to set. If omitted, or zero, the current length of the string is used.
If the Length is set to less than the current string length then the string is cropped to fit.
What (optional)Determines what trailing characters are removed. Possible options for this parameter are;
st:Spaces (This is the default value if the parameter is omitted.)
st:Tabs
st:cr
st:lf
st:zeros

These options can be added together. For example to remove trailing spaces and trailing tabs you can use
st.SetRight( ,st:spaces + st:tabs)
To remove all trailing spaces, tabs, carriage returns and linefeeds use
st.SetRight( ,st:spaces + st:tabs + st:cr + st:lf)
Pad (optional)Allows you to specify the character to use as the padding character if the length required is greater than the current string. If omitted then the default pad character is a space.

Return Value

Nothing. This method alters the current string value.

See Also

Right, Left, SetLeft

SetValue

SetValue (string NewValue, long pClip=false)
SetValue (stringTheory NewValue)


Description

Sets the value of the object to the parameter passed. The passed string can be of any size.

Parameters
Parameter Description
NewValue
(string)
A string, of any length.
pClipIf true then the string in NewValue is clipped. Only valid if NewValue is a string.
NewValue
(stringtheory)
Allows one StringTheory object to be set to the contents of another StringTheory object.

Notes

If the clip parameter is omitted (or False (0)) then the value being added to the string is not clipped, otherwise it is clipped. Defaults to not clipping the string.

If the value you are passing into the object is Base64 encoded, then set the Base64 property to 1 at the same time.

See Also

GetValue, Append

SetSlice

SetSlice (ulong pStart=1, ulong pEnd=0, string newValue)

Description

Sets the value of the specified region within the string to the passed string. The string is expanded if needed.

Parameters
Parameter Description
pStartStart position at which the replacement of the "slice" with the passed value begins.
pEndEnd position for replacement (if not specified this is calculated from the length of the passed newValue string.
newValueValue to overwrite the specified region with.
Return Value

None

Examples
Example
st.SetSlice(10, 20, '-NewValue-')

Slice

Slice (long Start, <long end>), string

Descriptions

Returns a substring of the current string. The current string is not altered.

If the end parameter is omitted then the string from the start position to the end of the string is returned.

Parameters
Parameter Description
startThe start position for the substring (slice) to be returned.
end [optional]The end position of the substring (slice) to be returned. If omitted this defaults to the length of the string.
Return Value

Returns the substring of the stored value from the start to end positions specified.

Example
Example
st      StringThory
  code
    st.SetValue('1234567890abcdefghikjlmnop')
    Message(st.Slice(10))      ! Displays: 0abcdefghikjlmnop
    Message(st.Slice(10, 13))  ! Displays: 0abc
See Also

Sub, SetLength, Between, FindBetween

Sort

Sort (Long SortType, string Boundary, [string Quote], [string QuoteEnd], bool Clip = false, bool Left=false)

Description

Note this method is only available in Clarion 6.3 (build 9050 and later.)

Splits the string into lines based on the Boundary parameter, sorts the lines based on the SortType parameter, then joins the lines back together in sorted order. In other words this method sorts the contents of the string, based on a separator string.

Parameters
Parameter Description
SortTypeOne of st:SortNoCase (case insensitive, alphabetic sort), st:SortCase (case sensitive, alphabetic sort) or st:SortLength (sorts the list by length of the line)
BoundaryThe Boundary parameter lets you specify the separating character.
Quote [optional] The optional Quote parameter allows you to specify a "quote" character which negates the boundary. For example in the following comma separated list, the double quote character wraps a string that negates the comma. For example:

Bruce Johnson, "Cape Town, South Africa"

Quotes are removed before sorting takes place.
QuoteEnd [optional] If the start, and end, quote characters are different, then the QuoteEnd parameter can be used. For example:

<Bruce Johnson>,<Cape Town, South Africa>

In this case the pQuote would be set to '<' and quoteEnd to '>'
If a string consists of multiple lines then the multi-character boundary '<13,10>' can be used.
Clip [optional]If this parameter is set to true, then each value in the string is clipped before sorting. The default for this parameter is false. If set to true then the resultant string will contain clipped values between the separators.
Left [optional]If this parameter is set to true, then leading spaces are removed from each value as the string is sorted. The default value of this parameter is false.
Return Value

None. The contents of the object are altered by this call. The Lines queue (as created by Split) is empty after this call.

See Also

Split, Join, Sort

Squeeze

Squeeze (long textType=ST:TEXT, <String pCharList>)

Removes excess white space (each word in the string is separated by a single space). By default punctuation is treated as white space and also "squeezed" (removed). Setting the textType parameter to ST:NOPUNCTUATION ensures that punctuation is not removed and is treated in the same manner as other none whitespace characters. With this option specified only extra spaces are removed.

Parameters
Parameter Description
textType [optional]Defaults to ST:TEXT (0), this removes all white space, tabs, line breaks and punctuation and results in each word in the string separated by a single space character.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character). This will result on only extra space characters being removed, not other characters are affected.
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:HTML.
Return Value

None

Start

Start()

This method frees the String object, clears out the Lines from a Split, and sets all the properties of the class back to the default setting. It is useful if you are re-using the object and you want to start it as if it had just been constructed.

Return Value

None

StartsWith

StartsWith (String Sub, <long Case>, <Long pClip>)

Description

Checks to see if the current object begins with a particualar sub string.

Parameters
Parameter Description
SubThe sub string to check for. If this string is empty then the method returns true.
CaseSet this to false if the test is case insensitive. The default value is true, meaning the test is case sensitive.
ClipIf this is true (the default) then the Sub string is clipped before comparing to the stored string. If set to false then any trailing spaces in the Sub parameter will need to match spaces in the string.
Return Value

True if there is a match, or the Sub parameter is empty or False if there isn't a match.

Example
Example
st     StringTheory
  code
  st.SetValue('123456789')
  x = st.StartsWith('89')    ! x is false at this point.
  x = st.StartsWith('')      ! x is true at this point.
  x = st.StartsWith('123')   ! x is true at this point.
See Also

EndsWith

Sub

Sub (long Start, <long length>), string

Description

Returns a substring of the current string. The current string is not altered.
If the length parameter is omitted then the single character at the Start position is returned.

See Also

Slice, SetSlice, Abbreviate

Str

Str (), string
Str (string newValue), string
Str (*string newValue), string


Description

Returns the current string value. If a string is passed then the passed value is first stored and then returned. This is the equivalent of calling SetValue() followed by GetValue()

Parameters
Parameter Description
newValue [Optional]An optional value to store before returning it.
Return Value

None

Examples
Example
Message(st.Str(someValue))

ToBlob

ToBlob (*blob blobField)

Description

Saves the current value to the passed BLOB.

Parameters
Parameter Description
*blob blobFieldThe BLOB field to store the value in.
Return Value

Returns True (1) for success or (0) for failure. If an error occurs the ErrorTrap() method is called with additional information.

Examples
Example
s.SetValue(plainText, true! Store a value in the StringTheory object
s.ToBlob(MailData.Text)     
! Store the value in the passed BLOB

ToBytes

ToBytes (*byte pSrc, *string pDest, long pOffset=1)
ToBytes
(*short pSrc, *string pDest, long pOffset=1)
ToBytes (*ushort pSrc, *string pDest, long pOffset=1)
ToBytes (*long pSrc, *string pDest, long pOffset=1)
ToBytes (*ulong pSrc, *string pDest, long pOffset=1)
ToBytes (*sreal pSrc, *string pDest, long pOffset=1)
ToBytes (*real pSrc, *string pDest, long pOffset=1)
ToBytes (*decimal pSrc, *string pDest, long pOffset=1)
ToBytes (*cstring pSrc, *string pDest, long pOffset=1)
ToBytes (*pstring pSrc, *string pDest, long pOffset=1)
ToBytes (*string pSrc, *string pDest, long pOffset=1)


Description

Retrieves the binary value from the pSrc parameter and stores it in the passed second string parameter variable at the offset determined by the third parameter. The actual bytes are moved from the source variable to the destination value. 
The final three forms of the method is a simple move from one string to another.

The opposite of the ToBytes method is the FromBytes method.

FromBytes and ToBytes to not use, or alter, the current contents of the StringTheory object. For an equivalent pair of methods that work on the object itself see GetBytes and SetBytes.

Parameters
Parameter Description
pSrcThe variable to store the binary value of.
pDestA string used to store the passed data as binary.
pOffsetThe offset index into the string for where to put the value to. If omitted then then the default position is the first character in the string.

Return Value


None

Example
Example
a   Long
s   String(10)
  code
  a = 041414141h
  str.ToBytes(a,s)
 
! s = 'AAAA'
  a = 042424242h
  str.ToBytes(a,s,5)
 
! s = 'AAAABBBB'

See Also


GetBytes , SetBytes , FromBytes

ToCString

ToCString ()

Description

Returns a pointer to a Cstring. The contents of the Cstring will be set to the current string. This is useful if you wish to pass the string to other functions that require a Cstring.

NOTE: POTENTIAL MEMORY LEAK WARNING: The Cstring is created using the NEW keyword. It is the responsibility of the programmer to DISPOSE this cstring. The FreeCstring() method can also be used to safely dispose the string reference.

Example
Example
c  &cstring
st StringTheory

 
code
    st.SetValue('
hello world')
    c &= st.ToCstring()
   
! use cstring here
    Dispose(c)

Trace

Trace ([string Message])
Trace ([queue pQueue])


Description

A method to send data to debugview, primarily for debugging purposes. If no paramter is used then the current contents of the string are sent to debugview.

Parameters
Parameter Description
MessageA string of any length which is sent to DebugView.
pQueueThe Queue is serialized (using the SerializeQueue method), and the result is sent to debugview.
this allows the contents of a Queue to be inspected as a comma separated list.

Notes

DebugView is a useful free utility provided by Microsoft for viewing the all output to the system debug log, as well as allowing it to be filtered, specified strings to be highlighted etc. DebugView is a free 286KB download, available for all version of Windows from XP onwards, from http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx.

A better version of DebugView is DebugView++. This can be found on Github at https://github.com/djeedjay/DebugViewPP.

Returns

Nothing


Trim

Trim (<String pAlphabet>)

Description

Removes white space from the start and the end of the string.

Parameters

Parameter Description
pAlphabetA string containing characters that are considered to be white space. In other words any characters at the front, or back of the string which are also in the pAlphabet string will be removed. Defaults to a space character.

Return Value

None. The object is updated by this method.

UnQuote

UnQuote (<string pQuotestart>,<string pQuoteEnd>)

Description

Removes the quotes wrapping the string. By default this removes double quotation marks at the start and end of the string, or the passed start and end quote characters.

Parameters
Parameter Description
pQuoteStartOptional character to use as the opening quotation mark. Defaults to a double quote (").
quoteEndOptional character to use as the closing quotation mark. Defaults to a double quote (").
Return Value

None

Examples
Example
st.UnQuote()  ! Removes double quotes wrapping the string

Upper

Upper ([String Quote],[String QuoteEnd])

Converts all the characters (except the ones in quotes) in the current string to upper case.

Parameters
Parameter Description
Quote (optional)A character to identify the start of Quoted Text. Quoted Text will not be uppered by this method. If this parameter is omitted then all the text in the string is uppered.
QuoteEnd (optional)The character to use as the end of Quoted Text. If omitted, and the Quote parameter is not omitted, then the same quote character will be used to delineate the start and end of text.
Example
Example
st  stringtheory
  code
  st.SetValue('This is a "test" of the UPPER method')
  st.lower('"')
  ! st now contains 'THIS IS A "test" OF THE UPPER METHOD'

Return Value


Returns nothing. The contents of the string are changed.

See Also

Lower , Capitalize

UrlDecode

UrlDecode ([String Delimiter],[String Space])

Description

URL (percent) decodes the string.

Parameters
Parameter Description
Delimiter [optional]The default delimiter for is a % character (hence the common name of "percent encoding". If you want an alternate character to be used then enter it here. Note that this field is limited to a single character.
Space [optional]The default encoding for the space character is a + character. If you want the space character to be encoded as something else then you can enter that here. note this field is limited to a single character.
Returns

Nothing

See Also

URLDecode

UrlEncode

UrlEncode (long Flags = 0, [String Delimiter], [String Space], [String Alphabet])
UrlEncode (String pText, long Flags, String Delimiter, String Space, String Alphabet)


Description

URL (percent) encodes the string. All non alpha-numeric characters are replaced with a delimiter, and a number (in Hex format) representing the number of the character in the ASCII table.

Parameters
Parameter Description
pTextThe text to encode. If this parameter is omitted then the current contents of the object will be used. If this parameter is used then all the other parameters are NOT optional and must be explicity set to something.
FlagsThe flag field is accumulative, and any combination of the following flags may be added together;
st:dos the following characters are not encoded; / \ . $
st:NoPlus The space character is not encoded.
st:BigPlus the space character is encoded as %20, not +
Delimiter The default delimiter for is a % character (hence the common name of "percent encoding". If you want an alternate character to be used then enter it here. Note that this field is limited to a single character.
Space The default encoding for the space character is a + character. If you want the space character to be encoded as something else then you can enter that here. note this field is limited to a single character.
AlphabetCharacters specified in this string will NOT be encoded, but left as-is.

Returns

Nothing

See Also

URLDecode

UrlFileOnly

UrlFileOnly(<string pURL>)

Description

Extracts the file part of a fully qualified URL. So given a string of the form
protocol://host:port/urlpath/file?parameters
file  is returned.

Parameters
Parameter Description
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used

Returns


A string. The filename  part of the URL. If the filename is omitted from the url then a blank string is returned.  The current string value is not altered by this method.

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
name = str.UrlFileOnly()
! name = 'index.htm'

str.setvalue('www.capesoft.com')
name = str.UrlFileOnly() ! name = ''

See Also

UrlProtocolOnly, UrlPortOnly, UrlHostOnly, UrlPathOnlyUrlParametersOnly

UrlHostOnly

UrlHostOnly(<string pURL>,Long pIncludePort=true)

Description

Extracts the host part of a fully qualified URL. So given a string of the form
protocol://host:port/urlpath/file?parameters
host or host:port is returned.

Parameters
Parameter Description
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used
pIncludePort (optional)Defaults to on. Allows you to include, or exclude the port part of the host name (if it exists).

Returns


A string. The host part of the URL. If the protocol is omitted from the url then a blank string is returned. The trailing :// part of the protocol is not included in the returned value. The current string value is not altered by this method.

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
host = str.UrlHostOnly()
! host = 'www.capesoft.com:80'

host = str.UrlHostOnly('http://www.capesoft.com:80/accessories/index.htm',false) ! host = 'www.capesoft.com'

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
host = str.UrlHostOnly( , false) ! host = 'www.capesoft.com'

See Also

UrlProtocolOnly, UrlPortOnly, UrlPathOnly, UrlFileOnly, UrlParametersOnly

UrlParameter

UrlParameter(String pParameter,<string pURL>)

Description

Extracts the value of a parameter in a URL.

Parameters
Parameter Description
pParameterThe name of the parameter to fetch. If the parameter exists multiple times with the same name then the first value is retrieved.
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used. This value can contain a URL complete with parameters (separated by a ? character) . A list of parameters, after the ? can also be passed without the URL part.

Returns


A string. The value of the named parameter. The value is already URL Decoded.

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm?user=charles&uid=1')
user = str.UrlParameter('user')
! user = 'charles'

str.setvalue('user=charles&uid=1')
user = str.UrlParameter('uid') ! uid = 1


See Also

UrlParametersOnly

UrlParametersOnly

UrlParametersOnly(<string pURL>)

Description

Extracts the parameters part of a fully qualified URL. So given a string of the form
protocol://host:port/urlpath/file?parameters
parameters is returned.

Parameters
Parameter Description
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used

Returns


A string. The parameters part of the URL (ie everything after the ? character. If there are not parameters in the URL then a blank string is returned. The leading ? character is not included in the returned value. The current string value is not altered by this method.

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm?user=charles&uid=1')
parameters = str.UrlParametersOnly()
! parameters = 'user=charles&uid=1'

str.setvalue('www.capesoft.com')
parameters = str.UrlParametersOnly()
! parameters = ''

See Also

UrlProtocolOnly, UrlHostOnly, UrlPortOnly, UrlPathOnly, UrlFileOnly , UrlParameter

UrlPathOnly

UrlPathOnly (<string pURL>, Long pIncludeFile=true)

Description

Extracts the URL part of a fully qualified URL. So given a string of the form
protocol://host:port/urlpath/file?parameters
urlpath or urlpath/file is returned.

Parameters
Parameter Description
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used
pIncludeFile (optional)If true then the filename is included in the return string.

Returns


A string. The path part of the URL. If the path is omitted from the URL then a blank string is returned. The leading / part, and trailing / part, of the path is not included in the returned value. The current string value is not altered by this method.

If the pIncludeFile parameter is true then

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
urlpath = str.UrlPathOnly()
! url = 'accessories/index.htm'

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
urlpath = str.UrlPathOnly( , false) ! url = 'accessories'

str.setvalue('www.capesoft.com/index.htm')
urlpath = str.UrlPathOnly()
! url = 'index.htm'

str.setvalue('www.capesoft.com/index.htm')
urlpath = str.UrlPathOnly(, false)
! url = ''

See Also

UrlProtocolOnly, UrlHostOnly, UrlPortOnly, UrlFileOnly, UrlParametersOnly

UrlPortOnly

UrlPortOnly (<string pURL>)

Description

Extracts the port part of a fully qualified URL. So given a string of the form
protocol://host:port/urlpath/file?parameters
port is returned.

Parameters
Parameter Description
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used

Returns


A Long. The port part of the URL. If the port is omitted from the url then a 0 is returned. The leading : part of the port is not included in the returned value. The current string value is not altered by this method.

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
port = str.UrlPortOnly()
! port = 80

str.setvalue('www.capesoft.com')
port = str.UrlPortOnly()
! port = 0


See Also

UrlProtocolOnly, UrlHostOnly, UrlPathOnly, UrlFileOnly, UrlParametersOnly

UrlProtocolOnly

UrlProtocolOnly (<string pURL>)

Description

Extracts the protocol part of a fully qualified URL. So given a string of the form
protocol://host:port/urlpath/file?parameters
protocol is returned.

Parameters
Parameter Description
pURL (optional)Contains the full URL to parse. If omitted, or blank, then the current contents of the string are used

Returns


A string. The protocol part of the URL. If the protocol is omitted from the url then a blank string is returned. The trailing :// part of the protocol is not included in the returned value. The current string value is not altered by this method.

Examples

str.setvalue('http://www.capesoft.com:80/accessories/index.htm')
protocol = str.UrlProtocolOnly()
! protocol = 'http'

str.setvalue('www.capesoft.com')
protocol = str.UrlProtocolOnly()
! protocol = ''

See Also

UrlHostOnly, UrlPortOnly, UrlPathOnly, UrlFileOnly, UrlParametersOnly

Word

Description

this method has been deprecated and removed from the class because of a name clash with the WORD EQUATE declared in some files. Use the GetWord method instead.

WordEnd

WordEnd (long pStartPos=1, long textType=ST:TEXT,<String pCharlist>)

Description

Returns the end position of the word when passed the start position. Returns 0 if the start position is invalid. Returns the position of the final character in the string if no white space is found before the end of the string. Also supports searching within a HTML string (handles escaped characters etc.). Note for HTML this won't skip over HTML tags, that needs to be handled by the caller.
Parameter Description
pStartPos [optional] The start position to begin search from. Defaults to the start of the string
textType [optional]Defaults to ST:TEXT (0) (the string is assumed to be normal text).

If set to ST:HTML (1) the string is assumed to be HTML encoded, so escape sequences such as '&nbsp;' and other encoded characters are not treated as words.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character.)
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:HTML and
'. ,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:CONTROLCHARS

Return Value

Returns the end position of the word when passed the start position. Returns 0 if the start position is invalid.
If the position is not in a word (ie it's already on punctuation) then 0 is returned.
Returns the position of the final character in the string if the no white space is found before the end of the string.

Example
Example
st.SetValue('Hello World.')
Message('Find words in: "' & st.GetValue() & '"')

sPos = st.WordStart()
ePos = st.WordEnd(sPos)
Message('First word: ' & st.Slice(sPos, ePos))

sPos = st.WordStart(ePos+1)
ePos = st.WordEnd(sPos)
Message('Second word: ' & st.Slice(sPos, ePos))
See Also

WordStart, CountWords

WordStart

WordStart (long StartPos=1, long textType=ST:TEXT, Long Dir=1,<String pCharlist>)

Description

Find the start of the next word in the string from the passed starting position. Also supports searching within data from an HTML string (handles escaped character etc.). Note for HTML this won't skip over HTML tags, that needs to be handled by the caller.

Parameters
Parameter Description
StartPos [optional]The start position to begin counting words from. Defaults to the start of the string
textType [optional] Defaults to ST:TEXT (0) (the string is assumed to be normal text).

If set to ST:HTML (1) the string is assumed to be HTML encoded, so escape sequences such as '&nbsp;' and other encoded characters are not treated as words.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character)
Dir (optional) If Set to st:Forwards (the default) then searches for the start of the next word.
If set to st:Backwards then searches for the start of the current word. If the StartPos points to whitespace then the start of the word before the whitespace will be returned.
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:HTML and
'. ,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:CONTROLCHARS
Return Value

Returns the start position of the next word.
Returns zero if no word is found, or if the passed pStartPos is greater than the length of the string.

Example
Example
st.SetValue('Hello World.')
Message('Find words in: "' & st.GetValue() & '"')
sPos = st.WordStart()
ePos = st.WordEnd(sPos)
Message('First word: ' & st.Slice(sPos, ePos))
sPos = st.WordStart(ePos+1)
ePos = st.WordEnd(sPos)
Message('Second word: ' & st.Slice(sPos, ePos))
See Also

WordEnd, CountWords , SplitIntoWords, GetWord

WrapText

WrapText (long wrapAt=80, bool keepExistingBreaks=true, bool pleft=false)

Description

Performs word wrapping to wrap the text to a fixed width by breaking lines as close the the specified width as possible. Lines are only broken on white space (tabs and spaces). The default wrap width is 80 characters.

Parameters
Parameter Description
wrapAt = 80The width to word wrap each line at. This is the maximum desired length for any line after wrapping. Note that this method only adds breaks at white space, so lines may be longer than the specified width if you do not contain any white space.
keepExistingBreaks=trueKeeps existing CR/LF's in the output. If this is false then existing line-breaks are removed. Regardless of the setting existing paragraph breaks are preserved.
pleft=falseIf true then each line is left-justified, ie leading white-space is removed.
Return Value

None

XMLDecode

XMLDecode()

Description

Decodes a string that has previously been encoded into the XML format. The &, < and > characters are decoded from &amp;, &lt; and &gt; respectively.

Return Value

Returns nothing. The current string is altered by this method.

See Also

XMLEncode

XMLEncode

XMLEncode(Long pOptions=0)

Description

Encodes a string so it is a valid XML string which can be used in an XML file. XML reserved characters (&, < and >) are encoded.

Parameters
Parameter Description
Options (optional)Reserved for future use.

Return Value


Returns nothing. The current string is altered by this method.

See Also

XMLDecode

Split, manipulate, and Join strings


The following methods are provided to split a string into parts, manipulate the parts, then (optionally) join the string back together again. This is a powerful way to take a string and manipulate the various parts of the string.

AddLine

AddLine (long LineNumber, String Value)

Description

Adds the value od the string to the queue, at the specific line number. Lines after this line are moved down by one. If the LineNumber parameter is greater than the lines in the queue, then the line is added to the bottom of the queue.

Delete

Line (long LineNumber)

Description

The line at the specified position is deleted. All lines after that line are moved up in the queue by one position. The function returns true if the line specified does not exist, or false otherwise.

FreeLines

FreeLines ()

Description

A method used to free the the Lines Queue populated by the Split command. This safely, and without leaking memory, empties the existing queue of lines.
See also the Split method. Note that the Lines queue will be safely disposed when the object destructs.

See Also

Split, RemoveLines, Filter, DeleteLine

GetLine

GetLine (long LineNumber)

Description

Returns the value of a specific line in the string, after calling the Split method.

See also the Split, SetLine methods.

InLine

InLine (string SearchValue, long Step=1, long Start=1, long End=0, long Nocase=0, long WholeLine=0, Long Where=st:anywhere)

Description

Searches the split lines for a specific string. Before calling this method you need to call SPLIT to split the string into lines.

Parameters
Parameter Description
SearchValueThe search term to look for in the lines.
Step (optional)The step from one line to the next. If omitted the default value is 1.
Start (optional)The first line number to check. If omitted the default value is 1.
End (optional)The highest line number to check. If omitted the default value is the number of lines. If less than the Start value, then is set to the Start value.
Nocase (optional)If set to true then a case in-sensitive search is made. If omitted or false then searches are case sensitive.
WholeLine (optional)If set to true then the SearchValue must match the contents of the whole line exactly. If omitted or false then the search looks for a sub string inside the line.
Where (optional)Set to one of st:begins, st:ends or st:anywhere. If this parameter is omitted then st:anywhere is used. If it is set to st:begins then the line needs to begin with the SearchValue. If set to st:ends then it needs to end with the SearchValue.

Returns

The line number of the located value. If the value is not found then it returns 0.

See also

Split, GetLine, SetLine

Split

Split (string Boundary, [String Quote],[string QuoteEnd],[RemoveQuotes = false],[Clip = false],[Left = false],[String Separator],Long Nested=false)

Description

The current string is "split" into a number of strings, which are then easily accessible in the Lines Queue. This allows for the easy parsing of "anything separated lists", for example the semi-colon separated lists used for emails, or the string returned from a multi-select FileDialog function.

Parameters
Parameter Description
boundaryThe Boundary parameter lets you specify the separating character.
Quote [optional] The optional Quote parameter allows you to specify a "quote" string which negates the boundary. For example in the following comma separated list, the double quote character wraps a string that negates the comma. For example:
Bruce Johnson, "Cape Town, South Africa"


This string would be parsed into 2 parts, the name and the address. The Quoting characters are included in the parsed result if the RemoveQuotes parameter is not set to true. In the above example the two strings after splitting are:
Bruce Johnson
"Cape Town, South Africa"


The quotes do not have to be at the beginning and end of the field in order to apply. Consider for example the following;

2,here,function(a,b){hello}

If the quote is set as ( and the endquote is set as ) then this will split into 3 lines;
2
here
function(a,b) {hello}


In some cases multiple quotes are necessary. Consider the string
2,function(a,b){add a,b},php

To resolve this to the 3 lines
2
function(a,b)<add a,b>
php

it's necessary to specify multiple boundaries in a "something" separated list. (See the Separator below for the something.) To achieve the result above (assuming the separator is a /) the quote parameter would be (/< and the endquote parameter would be )/>.

The Quote (and EndQuote) parameters are clipped. so spaces are not allowed.

QuoteEnd [optional] If the start, and end, quote strings are different, then the QuoteEnd parameter can be used. For example:

<Bruce Johnson>,<Cape Town, South Africa>

In this case the pQuote would be set to '<' and quoteEnd to '>'
If a string consists of multiple lines then the multi-character boundary '<13,10>' can be used.
RemoveQuotes [optional] If this is set to true then the quotes will be removed from the lines in the Lines Queue. Note that only quotes at the beginning or end of the string will be removed, quotes detected inside the string, although they will apply when splitting the string, will not be removed, even if this parameter is set to true.
Clip [optional]If this parameter is set to true, then the lines are clipped before adding them to the Lines Queue. This can be useful where the file being input contains large amounts of trailing whitespace (spaces) at the end of each line.
Left [optional]If this parameter is set to true, then leading spaces are removed from each line as the lines are created. The default value of this parameter is false.
Separator [optional]If this parameter exists, and is not blank, then the Quote and QuoteEnd parameters are treated as a list, where the list of possible Quote and QuoteEnd pairs are separated by this character. Note that the Quote and QuoteEnd must have the same number of items in them, and only the matching QuoteEnd item matches the Quote item.
The Separator should be a single character. Do not use the Space character as the Separator.
Nested [optional]It's possible that quote and EndQuote characters, if different, can be nested in the string being split. If you want to match the starting and ending pair, ignoring internally nested pairs then set this parameter to true. For example consider

(1,2) , (3,4) , ((5,6),7)

The above string has 3 terms, separated by a comma. Commas inside the brackets are ignored. In the third term though the brackets are nested, and in order to correctly split this into three terms the brackets around the 5,6 must be ignored. To do that set the Nested parameter to true.
Examples

Example
st.SetValue('12,bruce,"po box 511, plumstead"')
st.split(',','"')
! result is ! 12 ! bruce ! "po box 511, plumstead"
Example
st.SetValue('12,bruce,"po box 511, plumstead"')
st.split(',','"',true)
! result is ! 12 ! bruce ! po box 511, plumstead
Example
st.SetValue('[12,24,36],bruce,(po box 511, plumstead)')
st.split(',','[-(',']-)',false,,,'-')
! result is ! [12,24,36] ! bruce ! (po box 511, plumstead)

Return Value

None

Tip

It may be necessary to use the { } brackets as quote characters. In Clarion, in order to put the { character in a string, you need to type {{. Thus to split {a,b},{c,d} into two terms, the call to the Split method will be

st.split(',','{{','}')

See Also

Join, SplitEvery, GetLine, SetLine, AddLine, Records

SplitEvery

SplitEvery (long numChars)

Description

Splits the string in numChars lengths and stores each new substring as a line in the self.lines queue.

If the string is shorter than numChars then a single "line" entry is added which contains the string. If the string is not an exact multiple of numChars then the last substring split contains however many characters remain.

Parameters
Parameter Description
numCharsThe number of characters that each new substring should contain, i.e. the length to split the string up using
Returns

None

SplitIntoWords

SplitIntoWords(long StartPos = 1, long TextType=ST:TEXT, <String pCharlist>)

Description

Splits the string into words and stores each new word as a line in the self.lines queue.

Only the words are added to the queue, not the word separators, or punctuation, so the lines cannot be JOINed together to create the original string again.

Parameters
Parameter Description
StartPos [optional]The start position to begin splitting words from. Defaults to the start of the string
textType [optional] Defaults to ST:TEXT (0) (the string is assumed to be normal text).

If set to ST:HTML (1) the string is assumed to be HTML encoded, so escape sequences such as '&nbsp;' and other encoded characters are not treated as words.

Can also be set to ST:NOPUNCTUATION (2) which will not treat punctuation as white space (and hence punctuation is included in words as a normal character)
pCharList (optional) The list of characters which delineate the end of a word. The default value is
'. <13><10><9>,-;"''!?&()*/+=<>:'  when the TextType parameter is set to ST:TEXT and
'. <13><10><9>,-;"''!?&()*/+=<>:' when the TextType parameter is set to ST:HTML.
Returns

None

See Also

Split, WordStart

Join

Join (String Boundary, [String Quote],[string QuoteEnd], [AlwaysQuote])

Description

The opposite of the Split method. The current string value is cleared. The string is then constructed from the parts in the Lines Queue. The result is placed in the current value.
Each line is separated from the others using the Boundary parameter.

If a Quote parameter is used, and a line contains the boundary character(s), then the line will be prefixed by the Quote parameter (if it isn't already). The line will also be ended by either the QuoteEnd parameter (if it exists) or the Quote Parameter. If the

Parameters
Parameter Description
BoundaryThe character(s) to place between the lines in the eventual string.
QuoteAn optional start quote to wrap text which contains the boundary character.
QuoteEndAn optional endquote. If omitted the start quote is used.
AlwaysQuoteIf true then the line is always wrapped in quotes, even if the text does not contain a Boundary.

Returns


Nothing.   The Lines Queue remains as-is after this call. It is not cleared. The Object is updated to contain the concatenated lines.

See also

Split, SplitEvery, Records

RemoveLines

RemoveLines ([string Alphabet])

Description

This method works on the Lines created by the Split method.  It removes empty lines from the queue (allowing you to specify which characters are included in the definition of emptyness.)
 
Parameters
Parameter Description
Alphabet (optional)By default empty lines are lines which only include spaces. If the Alphabet parameter is used then you can include other characters in the definition of emptyness.
Example
Example
st.Split(',')
st.removeLines()
! removes lines with only spaces
st.removeLines('<9,10,13>) ! removes lines with only tab, space, cr and lf characters.

Returns

The number of lines removed.

See also

FreeLines, Filter

Records

Records ()

Description

Returns the number of lines parsed after a call to the Split method.

See also

Split

SetLine

SetLine (long LineNumber, String Value)

Description

Sets the value of a specific line in the string, usually after calling the Split method. If the line does not exist, then the string is added at the end of the queue (ie in the next available line.)

See also

Split, GetLine methods.

Sort

Sort (Long SortType)

Description

Note this method is only available in Clarion 6.3 (build 9050 and later.)

Sorts the lines, created by the Split method. Three sorts are offered, case sensitive, case insensitive and length.

Parameters
Parameter Description
SortTypeOne of st:SortNoCase (case insensitive, alphabetic sort), st:SortCase (case sensitive, alphabetic sort) or st:SortLength (sorts the list by length of the line)
See also

Split, GetLine, Sort methods.

Filter

Filter (string Include, string Exclude)

Description

This method works on the Lines created by the Split method. It allows you to delete some of the lines, based on an Instring of that line. It is possible to specify both an include, and an exclude at the same time.

Parameters
Parameter Description
IncludeIf the Include parameter is not an empty string, then all lines not containing that string will be removed.
Exclude If the Exclude parameter is set then all lines containing that string will be removed. Exclude is applied after Include, and will remove a line even if the Include line has specifically included it.

 See Also

RemoveLines

Formating and Deformating

Converting Strings between raw data and display using display pictures.

DeformatTime

DeformatTime ([String Value])

Description

An incoming string value, representing time in "human" terms is converted to a standard Clarion time value, suitable for storing in a LONG. Note that a time picture is not needed here. The method will determine the incoming picture and will deformat it appropriately.

Parameters
Parameter Description
ValueIf the Value parameter is omitted then the current string value is used, and the current string value is changed to the Clarion time number. If a value is provided then the Clarion number is returned from the method and the existing string value in the object is not changed.
Return Value

If the Value parameter is omitted then nothing is returned.
If a value is provided then the Clarion number is returned.

See Also

IsTime,FormatTime

FormatTime

FormatTime ([Long Value],String Format)

Description

An incoming Clarion standard time value is converted to a human-readable format. The format parameter is required to determine the exact human-readable form of the time.
Support for a time value > 23:59:59 is supported (for totalling hours, etc).

Parameters
Parameter Description
ValueIf the Value parameter is omitted then the current string value is used, and the current string value is changed to the human-readable format. If a value is provided then a string value is returned from the method and the existing string value in the object is not changed.
FormatThe format string determines the exact format of the result. The string is made up of the following parts. (optional parts are encased in [ square brackets ].

[@][T]n[s][B][Z]

@, T : optional. Not required by this method, but allowed.

nn : up to a 5 digit number.  A leading 0 indicates zero-filled hours (hh). Two leading zeros (hhh), Three leading zeros (hhhh). The number after the zeros determines the format to use. See below.

s : separator. Can be an underscore (spaces will be used as a separator), a quote character (commas will be used), a period (periods will be used) or a hyphen (hyphens will be used). If omitted then colons will be used as the separator.

B : Set to blank if time is < 0. Also blank if value is 0 and Z attribute is not used.

Z : Time is formatted as "base 0"- in other words 0 = 0:00 and 360000 = 1:00. If left off then the default Clarion approach (base 1) is used. In "base 1" 0 is undefined, 360001 = 1:00 and so on.

@T1 hh:mm 17:30
@T2 hhmm 1730
@T3 hh:mmXM 5:30PM
@T03 hh:mmXM 05:30PM
@T4 hh:mm:ss 17:30:00
@T5 hhmmss 173000
@T6 hh:mm:ssXM 5:30:00PM
@T7 Windows Control Panel setting for Short Time (*)
@T8 Windows Control Panel setting for Long Time (*)
@T91 hh:mm:ss:cc 17:30:00:19
@T92 hh:mm:ss:ccXM 5:30:00:19pm

(*) these formats do not support times > 23:59
  

Return Value


If the Value parameter is omitted then nothing is returned.
If a value is provided then the Clarion number is returned.

See Also

IsTime,DeformatTime

Base Conversion, Hexadecimal Encoding and Byte Ordering

The following methods are provided to convert numbers between bases. Frequently used bases include 2 (binary) and 10 (decimal) and 16 (hexadecimal)

ToHex

ToHex (Long pCase=ST:LOWER)

Description

Converts the stored string to a hexadecimal string. Each byte is converted to two characters which represent the value of that byte (0 to 255). For example 'Hello World' would be encoded to: '48656c6c6f20576f726c64'. This is generally used for encoding small amounts of binary data in a human legible form (for example the value of a hash).

If the pCase parameter is set to ST:UPPER or ST:LOWER then the result will use that case. The default is ST:LOWER.

FromHex

FromHex ()

Converts the stored string from hexadecimal encoding back to the original value. Every two characters in the string represent the value of a byte (0 to 255). For example '48656c6c6f20576f726c64' would be decoded back to: 'Hello World'.

Base conversion

DecToBase

DecToBase (long num, long base=16, long lowerCase=1), string, virtual

Description

Converts a decimal number to a number using the specified base (such as Hexadecimal - base 16). The number is returned as a string of ASCII characters representing the number in the specified base. For example passed 255 will return 'ff'.

BaseToDec

BaseToDec Procedure (string num, long base=16), long, virtual

Description

Converts the string of characters representing a number in a base other than 10 to a decimal and returns a long that contains the value. For example passed 'ff' will return 255 when the base is set to 16 (hexadecimal).

The method is case insensitive. Supports bases from 2 to 36. "Out of range" digits, including spaces, commas and periods are ignored.

Byte based conversion to hex

ByteToHex

ByteToHex (byte pByte), string, virtual

Converts a byte to a two character string that contains the hexadecimal equivalent of the byte value. For example a byte that contains 255 would return 'ff'.

Parameters
Parameter Description
pByteA byte which contains value to convert to a hexadecimal string. Return values range from '00' for a byte value of 0 to 'ff' for a byte value of 255. Hexadecimal characters 'a' through to 'f' are returned as lower case.
Return Value

Returns string which contains the hexadecimal equivalent of the passed value.

LongToHex

LongToHex (long pLong), string, virtual

Description

Converts a long integer (4 bytes) to a hexadecimal string. Returns a string that contains the hexadecimal of each byte in big endian order (the most significant byte first).

For example:

The value 255 would be stored as four bytes with the decimal values: 00 00 00 255, and the hexadecimal values: 00 00 00 FF; and LongToHex would return the string: '000000ff'.

12 128 72 57, the hexadecimal values: 0C 80 48 39; and LongToHex would return a string: '0c804839'

Parameters
Parameter Description
pLongA long that contains the value to convert to a hexadecimal string.
Return Value

Returns a string that contains the hexadecimal representation of the number passed. The string returned will always be 8 characters (bytes) long as each byte in the passed integer is presented by a pair of characters.
Examples
Example
st         StringTheory
  code
    Message('255 -> ' & st.LongToHex(255) & ', 209733689 -> ' &
    st.LongToHex(209733689 ))

    ! Displays:
	! 255 -> 000000ff, 209733689 -> 0c804839

StringToHex

StringToHex (string binData, Long pLen=0, Long pCase=0), *string, virtual

Description

Returns a string containing ASCII characters representing the hexadecimal values of each byte in the input string. This can be used to encode binary (or any other data) in a form that only uses ASCII text and is suitable for display. The returned string is twice the size of the original, so for more efficient encoding use the Base64 encoding methods.

If the pLen parameter is omitted, or set to 0, then the string is clipped before conversion.

The pCase parameter can be omitted, or set to ST:UPPER or ST:LOWER. This will force the resultant Hex values to be in either upper or lower case.

Important: You must dispose the returned string once it is not longer needed in order to avoid leaking memory.

See Also

ToHex

HexToString

HexToString (string hexData), *string, virtual

Description

Returns a string containing the original data after decoding the input string of pairs of ASCII characters representing the hexadecimal value of each of the bytes in the output string.

Important: You must dispose the returned string once it is not longer needed in order to avoid leaking memory.

BigEndian

BigEndian (ulong x), ulong, virtual

Description

This method works on a long. To change the current string to big endian byte order see BigEndian.

Returns a Big Endian long when passed a Little Endian one (the byte order is reversed).

"Little Endian" means that the low-order byte of the number is stored in memory at the lowest address (first), and the high-order byte at the highest address (last). The little end comes first. "Big Endian" means that the high-order byte of the number is stored in memory at the lowest address (first), and the low-order byte at the highest address (last). The big end comes first.
Parameters
Parameter Description
xThe number to convert from Little Endian to Big Endian byte order
Return Value

Returns a ulong that contains the bytes in the opposite order to those in the passed parameter.

See Also

LittleEndian, ReverseByteOrder

LittleEndian

LittleEndian (ulong x), ulong, virtual

Description

This method works on a long. To change the current string to little endian byte order see LittleEndian.

Returns a Little Endian long when passed a Big Endian one (the byte order is reversed).

"Little Endian" means that the low-order byte of the number is stored in memory at the lowest address (first), and the high-order byte at the highest address (last). The little end comes first. "Big Endian" means that the high-order byte of the number is stored in memory at the lowest address (first), and the low-order byte at the highest address (last). The big end comes first.

Parameters
Parameter Description
xThe integer to convert to Little Endian
Return Value

Returns a ulong that contains the bytes in the opposite order to those in the passed parameter.

See Also

BigEndian, ReverseByteOrder

ReverseByteOrder

ReverseByteOrder (), virtual

Reverses the byte order of the string being stored. The entire string is reversed, so '123456ABC' would become 'CBA6543321'. This is useful when transferring data between systems which stored the bytes in different orders (such as certain file formats, operating systems, network protocol, cryptography etc.).

Parameters

None

Return Value

None

See Also

BigEndian, LittleEndian

Unicode Encoding, Conversion and Handling

The following methods provide handling for Unicode text, conversion between encoding types, and conversion between ANSI and Unicode text.

ToAnsi

ToAnsi (long encoding=0, [ulong CodePage], [Long pBlockSize]), long, proc

Description

Converts the current Unicode (UTF-8 or UTF-16) string to ANSI. If the encoding parameter is not passed to specify the encoding of the string then encoding property of the class must be set to the correct value to indicate the current encoding. If the text has been converted from ANSI to Unicode using the ToUnicode method, then this is done by the object, otherwise it needs to be set to one of the following:

st:EncodeUtf8 equate(1)
st:EncodeUtf16 equate(2)

Parameters
Parameter Description
encoding (optional) Specifies the encoding of the stored string. If this is not passed to specify the encoding of the string then .encoding property of the class must be set to the correct value to indicate the current encoding. If the text has been converted from ANSI to Unicode using the ToUnicode method, then this is done by the object, otherwise it needs to be set to one of the following:

st:EncodeUtf8 equate(1)
st:EncodeUtf16 equate(2)
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.
pBlockSize   (optional) Converting UTF-8 to ANSI can be quite memory intensive since the string is first converted to UTF-16 and then to UTF-8. This means a 100 Meg string will require 200 Megs of Extra ram just to convert.

By setting this setting you can set a "blocksize" which the conversion will use, converting 1 block at a time. This minimizes extra memory requirements (and can also be faster for large strings.)

This value is in Megabytes. It should be in the range of 1 to 50. If set to 0 the default blocksize (10 megs) is used. If set to more than 50 then 50 megs is used.
Return Value

Returns True (1) for success and False (0) for failure.

See Also

ToUnicode

ToUnicode

ToUnicode Procedure (long encoding =st:EncodeUtf8, [ulong CodePage]), long, proc

Description

Converts the current string to Unicode format (UTF-8 or UTF-16 ).
The current string can be ANSI or a Unicode format.

Supported encoding types for the encoding parameter are:

st:EncodeUtf8 equate(1)
st:EncodeUtf16 equate(2)


Parameters
Parameter Description
encoding (optional)Specifies the encoding to convert the passed string to. Defaults to UTF-8.
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.
Return Value

Returns True (1) for success and False (0) for failure. If an error occurs then the ErrorTrap method is called with additional information.

See Also

ToAnsi

Conversion between ANSI and UTF-16

AnsiToUtf16

AnsiToUtf16 Procedure(*string strAnsi, *long unicodeChars, ulong codepage=st:CP_US_ASCII), *string

Converts a standard ANSI string to a UTF-16 encoded Unicode string. Note that the converted string uses 16 bits (two bytes) per character. The unicodeChars parameter is set t the number of characters returned - this is not the number of bytes in the returned string (the Unicode string uses two bytes per character with UTF-16 encoding).

Parameters
Parameter Description
strAnsiA string which contains the ANSI text to convert to Unicode
unicodeCharsA long which will be set to the number of Unicode characters on return. Not that this is not the length of the string returned, but the number of Unicode characters stored in the string.
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.
Return Value

Returns a pointer to a string that contains the Unicode text if successful and Null if it fails.

Important
: The caller is responsible for disposing the returned string to ensure that the application does not leak memory!

Examples
Example
st           StringTheory
ansiText     string(255)
unicodeText  &string
unicodeLen   long
  code
  ansiText = 'Hello World'
  unicodeText &= st.AnsiToUtf16(ansiText, unicodeLen)
  ! Use the unicodeText and then Dispose it once done:
  Dispose(unicodeText)

Utf16ToAnsi

Utf16ToAnsi (*string unicodeString, *long ansiLen, long unicodeChars=-1, ulong codepage=st:CP_US_ASCII), *string

Description

Converts a UTF-16 encoded Unicode string to a ANSI string.

Parameters
Parameter Description
unicodeStringA string which contains the Unicode text. If unicodeChars is not passed to specify the number of Unicode characters in the string to convert, then the string should be null terminated.
ansiLenThe passed long will be set to the length of the returned string.
unicodeChars (optional)The number of Unicode characters in the passed string to convert. If this is not passed then the unicodeString parameter should be null terminated.
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.
Return Value

Returns a pointer to a string which contains the ANSI text if successful and Null if it fails.

Important: The caller is responsible for disposing the returned string to ensure that the application does not leak memory!

Examples
Example
st           StringTheory
ansiText     &string
ansiLen      long
code
  ansiText &= st.Utf16ToAnsi(unicodeText, ansiLen)
  ! Use the ansiText and then Dispose it once done:
  Dispose(ansiText)

Conversion between UTF-8 and UTF-16

Utf8To16

Utf8To16 Procedure (*string strUtf8, *long unicodeChars), *string

Description

Converts the passed UTF-8 string to UTF-16 and returns a string that contains the new UTF-16 encoded Unicode text.

Parameters
Parameter Description
strUtf8The UTF-8 encoded string
unicodeCharsOn return this is set to the number of characters in the returned string. Note that this is not the size of the string returned, but the number of characters that it contains.
Return Value

Returns a pointer to a string which contains the UTF-16 Unicode text if successful and Null if it fails.

Important: The caller is responsible for disposing the returned string to ensure that the application does not leak memory!

Utf16To8

Utf16To8 Procedure (*string unicodeString, *long utf8Len, long unicodeChars=-1), *string

Description

Converts the passed UTF-16 encoded text to UTF-8 encoding.

Parameters
Parameter Description
unicodeStringA string which contains the UTF-16 encoded Unicode text to convert to UTF-8. This string should either be null terminated, or the unicodeChars parameter should be passed to specify the number of Unicode characters to convert.
utf8LenOn return this is set to the length of the returned UTF-8 string.
unicodeChars [optional]The number of characters to convert. Defaults to -1, which assumes that the passed unicodeString is null terminated.
Return Value

Returns a pointer to a string which contains the UTF-8 Unicode text if successful and Null if it fails.

Important: The caller is responsible for disposing the returned string to ensure that the application does not leak memory!

Utf16ToUtf8Char

Utf16ToUtf8CharProcedure (String p_utf16Char,*Long rLen),string

Description

Converts the passed UTF-16 encoded text to UTF-8 encoding.

Parameters
Parameter Description
p_utf16CharA string, 2 bytes long, containing a utf-16 character.
rLenA Long variable which will be set to the length of the returned string
Return Value

Returns a string of 1,2 or 3 bytes long which contains the same character but in utf-8 format, not utf-16 format.

Conversion between ANSI and UTF-8

Utf8ToAnsi

Utf8ToAnsi (*string strUtf8, *long ansiLen, [ulong CodePage]), *string, virtual

Description

Convert the UTF-8 string to an ANSI string

Parameters
Parameter Description
strUtf8 [in]A string that contains the UTF-8 encoded text to convert to ANSI.
ansiLen [out]On return this is set to the length of the returned ANSI string in bytes.
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.
Return Value

Returns a pointer to a string which contains the standard ANSI text if successful and Null if it fails.

Important: The caller is responsible for disposing the returned string to ensure that the application does not leak memory!

AnsiToUtf8

AnsiToUtf8 Procedure (*string strAnsi, *long utf8Len, [ulong CodePage]), *string, virtual

Description

Convert ANSI encoded text to UTF-8 encoded Unicode text

Parameters
Parameter Description
strAnsi [in]The ANSI encoded text to convert
utf8Len [out]Set to the length of the UTF-8 encoded string returned
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.
Return Value

A pointer to a string that contains the UTF-8 encoded Unicode text if successful and Null if it fails.

Important: The caller is responsible for disposing the returned string.

BigEndian

BigEndian()

Description

This method works on a string. To change a Long to big endian byte order see BigEndian.

If the current string is encoded as utf-16, then ensures that the string is in Big-Endian order. Windows uses little endian, however it may be necessary to swap the byte order if communicating with a program that requires BigEndian strings.

If the incoming string has a byte-order-mark then the current encoding can be set from this mark. This is done automatically by SetEncodingFromBOM when the LoadFile, ToUnicode or ToAnsi methods are used, however if a string comes from another source then this will need to be done manually.

If the string is already in BigEndian mode then the string is left unaltered. If the string is not currently marked as being utf-16 encoded, then the string is unaltered.

Return Value

Nothing

See Also


LittleEndian, SetEncodingFromBOM, AddBOM

DecodeHexInline

DecodeHexInline Procedure ([string pId, Long pLength], [ulong pCodePage]), *string, virtual

Description

Converts an ANSI string, containing encoded unicode characters, to an ANSI string of the specified code page, where the characters are decoded.

Parameters
Parameter Description
pID [in] (optional)The identifier before the encoding. For example \u or \x or whatever the string contains.
Length [in]
[optional, but required if pID is passed)
The length of the encoding. Usually (but not always) 2 characters with /x and 4 characters with /u

If the pID and length are both omitted then the string is tested for both \xHH and \uHHHH.
CodePage (optional) Specifies the CodePage that should be used to contain the result. The default is st:CP_US_ASCII. Other code pages are st:CP_WINDOWS_1250 through st:CP_WINDOWS_1258 and st:CP_ISO_8859_1 through st:CP_ISO_8859_15.

Example

str.SetValue('\x41zi\u00ebhavenweg')
str.DecodeHexInline(st:CP_WINDOWS_1250)
! string value is now Aziëhavenweg

In the above example \x precedes a 2 digit hex code (41) which is the ANSI character A.
\u precedes a 4 character hex code (00EB) which when converted to ANSI, using code page Windows-1250 is the character ë.

Return Value

A pointer to a string that contains the UTF-8 encoded Unicode text if successful and Null if it fails.

Important: The caller is responsible for disposing the returned string.

LittleEndian

LittleEndian()

Description

This method works on a string. To change a Long to little endian byte order see LittleEndian.

If the current string is encoded as utf-16, then ensures that the string is in Little-Endian order. Windows uses little endian for all APIs.

If the incoming string has a byte-order-mark then the current encoding can be set from this mark. This is done automatically by SetEncodingFromBOM when the LoadFile, ToUnicode or ToAnsi methods are used, however if a string comes from another source then this will need to be done manually.

If the string is already in LittleEndian mode then the string is left unaltered. If the string is not currently marked as being utf-16 encoded, then the string is unaltered.

Return Value

Nothing

See Also


BigEndian, SetEncodingFromBOM, AddBOM

StringTheory Property Reference

base64 longSet to True (1) if the string currently in the object is Base64 encoded. Set to False (0) if not.
base64nowrapboolIf set to True (1) then no line wrapping is done when Base 64 encoding a string. By default lines are wrapped by inserting a carriage return, line feed pair (ASCII 13,10) to limit the line length to 80 characters including the CR,LF pair.
BytesLongReturns the number of bytes loaded after a call to the LoadFile method.
CleanBufferLongIf this is set to true, then the SetValue method will clear the contents of the whole buffer when assigning a new value to the string. This takes longer, but may assist programs that assumed that unused parts of the buffer will be cleared.
GzippedboolSet to True (1) when a string has been compressed by the Gzip method, and is available for decompressing with the Gunzip method.

Note that if a zipped file is loaded, using LoadFile, then this property should manually be set to 1 before the string can be decompressed.
lines queueA queue of strings populated by the Split method. The queue contains a single property Line. While you can access the lines queue, and the lines.line component directly, be careful because the lines property is a pointer to a string of variable length. Where possible the methods AddLine, SetLine, GetLine and DeleteLine should be used as these are safer.
logErrorslong Set to True (1) then errors sent to the ErrorTrap method will be forwarded to the Trace method, for output to the DebugView logging tool.
lastErrorstring The last error message passed to the Errortrap method. note that this value is not cleared when a successful call it made - it is the last error message passed to ErrorTrap, whenever that occurred.
valuestring (Private) The current value of the string. You should use the GetValue and SetValue methods to access the string, rather than accessing the property directly.
winErrorCode long The Windows Error code generated by the LoadFile or SaveFile method.
encodinglong Text encoding. This can be set before calling the ToUnicode method to specify the encoding to be used, or before calling ToAnsi to specify the Unicode encoding to convert. It will also be set by the ToUnicode and ToAnsi methods to the encoding of the string after successful conversion.

May be one of the following values:

st:EncodeAnsi equate(0)  !Standard ANSI text.
st:EncodeUtf8 equate(1)  !UTF-8 encoded Unicode text
st:EncodeUtf16 equate(2) !UTF-16 encoded Unicode text
endianlong One of st:LittleEndian or st:BigEndian. Only applicable when encoding = st:EncodeUtf16.

StringPicture Class

StringPicture Class Reference Introduction

Clarion uses format strings when displaying data on the screen or on a report. These format strings are known as PICTURES. A variety of picture types exist, including pictures for Dates, Times, Numbers and so on. These format strings are used by the Clarion FORMAT and DEFORMAT commands.

In order to manipulate pictures in code it is necessary to be able to parse a picture into it's component parts, examine or alter each part, and then recombine the parts to the format string. This class assists in performing these functions.

Using StringPicture

Two primary methods, ParsePicture and CreatePicture are used to parse an existing picture into parts, or to create a picture from parts. Each picture type supports a number of properties. A typical use-case might be to parse a picture simply to know what the picture consists of. Another use case might be to parse a picture, change an element, and then put the picture back together again.

Example

Consider the picture @N-10.2
this displays a number, with a leading - sign (if the value is negative.)
To change this picture to surrounding negative numbers in brackets, you would do something like this;

spic  StringPicture
  code
  spic.ParsePicture('@N-10.2')
  spic.SignBefore = '('
  spic.SignAfter = ')'
  result = spic.CreatePicture('N')

StringPicture Method Reference

CreatePictureCreate a Clarion picture from the current properties.
ParsePictureParse a picture string into its component parts

CreatePicture

CreatePicture(String pType)

Description

Takes the current properties, and constructs a Clarion picture from them.

Parameters
Parameter Description
pTypeIndicates the type of picture desired and hence the properties that will be used to create the picture.
Valid options are S, D, T, N, E, P or K.
Return Value

Returns the Clarion picture. The picture is also placed in the pic property for later use if desired.

See also

ParsePicture

ParsePicture

ParsePicture(<String pPic>)

Description

Takes a Clarion picture and parses it into its component parts. These parts are then made available as properties. The exact properties used varies from one picture type to the next.

Parameters
Parameter Description
pPicThe Clarion picture to parse. If omitted then the current value in the pic property is parsed.
Return Value

Returns the length of the resultant string. The contents of the string object are modified with the shortened string.

See also

CreatePicture

StringPicture Properties

Date Pictures
FillString(1)If set to '0' then dates are zero padded.
nString(3)The Date Picture Format.
sString(2)Separation character. Only one char is valid for date pictures.
DirectionString(1)< or > to indicate intellidate direction.
RangeString(2)a 2 digit number.
BString(1)If set to 'B' then the field is blank if zero.
Key-In Pictures
PatternString(255)The Key-In pattern.
BString(1)If set to 'B' then the field is blank if zero.
Number and Currency Pictures
CurrencyBeforeString(10)If set to '$' or '~Whatever~' then shown to the left of the number.
SignBeforeString(1)set to '-' or '(' or leave blank.
FillString(1)If set to '0' then dates are zero padded.
SizeString(6)A number, containing the number of characters in the formatted string.
GroupingString(1)The grouping char for each 3 digit group.
SeparatorString(1)The Decimal Separator.
PlacesString(6)The number of digits after the decimal separator.
SignAfterString(1)set to '-' or ')' or leave blank.
CurrencyAfterString(10)If set to '$' or '~Whatever~' then shown to the right of the number.
BString(1)If set to 'B' then the field is blank if zero.
Pattern Pictures
PatternString(255)The pattern.
BString(1)If set to 'B' then the field is blank if zero.
Scientific Pictures
mString(6)A number, containing the number of characters in the formatted string.
sString(2)The Decimal Separator.
nString(6The number of digits after the decimal separator.
BString(1)If set to 'B' then the field is blank if zero.
String Pictures
LengthString(4)A number, containing the number of characters in the formatted string.
Time Pictures
FillString(1)If set to '0' then dates are zero padded.
nString(3)The Time Picture Format.
sString(2)Separation character. Only one char is valid for time pictures.
BString(1)If set to 'B' then the field is blank if zero.

Support and Purchase

This template is copyright © 2010-2015 by CapeSoft Software. 

Your questions, comments and suggestions are welcome.  You can also contact us in one of the following ways:
CapeSoft Support
Email
Telephone +27 21 715 4000
Fax +27 21 715 2535
Post POPO Box 511, Plumstead, 7801, Cape Town, South Africa
StringTheory may be purchased from:
CapeSoft Sales
WWeb www.capesoft.com
Email sales at capesoft dot com
Telephone +27 21 715 4000
Fax +27 21 715 2535
Post PO Box 511, Plumstead, 7801, Cape Town, South Africa

Buy Online
Web Buy now at ClarionShop
www.clarionshop.com

History

If you are upgrading from StringTheory 1.xx then be sure to read Upgrading.

Version 2.66  6 September 2017 Version 2.64  23 August 2017

Thanks to Geoff Robinson who contributed many of the changes in this release. Version 2.63  27 July 2017 Version 2.62  7 June 2017 Version 2.61  31 May 2017 Version 2.60  15 May 2017 Version 2.59  12 May 2017 Version 2.58  11 April 2017 Version 2.57  2 March 2017 Version 2.56  22 February 2017 Version 2.55  21 February 2017 Version 2.54  6 February 2017 Version 2.53  3 January 2017 Version 2.52  19 December 2016 Version 2.51  27 October 2016 Version 2.50  16 September 2016 Version 2.49  7 September 2016 Version 2.48  30 August 2016 Version 2.47 5 August 2016 Version 2.46 7 July 2016 Version 2.45 6 July 2016 Version 2.44 29 April 2016 Version 2.43 29 November 2015 Version 2.42 23 November 2015 Version 2.41 13 November 2015 Version 2.40 4 November 2015 Version 2.39 3 November 2015 Version 2.38 15 September 2015 Version 2.37 10 September 2015 Version 2.36 29 August 2015 Version 2.35 13 August 2015 Version 2.34 28 July 2015 Version 2.33 24 July 2015 Version 2.32 15 July 2015 Version 2.31 14 July 2015 Version 2.30 9 July 2015 Version 2.29 30 June 2015 Version 2.28 19 June 2015 Version 2.27 16 June 2015 Version 2.26 19 May 2015 Version 2.25 18 May 2015 Version 2.24 15 May 2015 Version 2.23 14 May 2015 Version 2.22 4 May 2015 Version 2.21 7 April 2015 Version 2.20 7 April 2015 Version 2.19 24 March 2015 Version 2.18 23 March 2015 Version 2.17 20 March 2015 Version 2.16 19 March 2015 Version 2.15 25 February 2015 Version 2.14 5 January 2015 Version 2.13 1 December 2014 Version 2.12 29 November 2014 Version 2.11 27 November 2014 Version 2.10 25 November 2014 Version 2.09 1 September 2014 Version 2.08 30 June 2014
Version 2.07 29 May 2014
Version 2.06 26 May 2014
Version 2.05 15 May 2014
Most changes in this build courtesy of Geoff Robinson Version 2.04 20 March 2014
Some changes in this build courtesy of Geoff Robinson Version 2.03 14 March 2014 Version 2.02 11 March 2014 Version 2.01 10 March 2014 Version 2.00 27 February 2014
Some changes in this build courtesy of Geoff Robinson Version 1.97 10 February 2014 Version 1.96 31 January 2014 Version 1.95 21 January 2014 Version 1.94 13 January 2014 Version 1.93 14 November 2013 Version 1.92 12 August 2013
Version 1.91 10 July 2013
Version 1.90 20 June 2013 Version 1.89- 10 June 2013 Version 1.88- 30 May 2013 Version 1.87 - 27 May 2013 Version 1.86 - 22 May 2013 Version 1.85 - 9 May 2013 Version 1.84 - 2 May 2013 Version 1.83 - 2 May 2013 Version 1.82 - 1 May 2013 Version 1.81 - 29 April 2013 Version 1.80 - 25 April 2013 Version 1.79 - 23 April 2013 Version 1.78 - 14 March 2013 Version 1.77 - 7 March 2013 Version 1.76 - 27 February 2013 Version 1.75 - 21 February 2013 Version 1.74 - 20 February 2013 Version 1.73 - 15 February 2013 Version 1.72 - 25 January 2013 Version 1.71 - 3 January 2013 Version 1.70 - 27 December 2012 Version 1.69 - 10 December 2012 Version 1.68 - 20 November 2012 Version 1.67 - 12 November 2012 Version 1.66 - 2 November 2012 Version 1.65 - 31 October 2012 Version 1.64 - 12 October 2012 Version 1.63 - 27 August 2012 Version 1.62 - 20 July 2012 Version 1.61 - 19 June 2012 Version 1.60 - 24 May 2012 Version 1.59 - 14 May 2012 Version 1.58 - 25 April 2012 Version 1.57 - 17 April 2012 Version 1.56 - 20 February 2012 Version 1.55 - 15 February 2012 Version 1.54 - 12 January 2012 Version 1.53 - 4 January 2012 Version 1.52 - 22 November 2011 Version 1.51 - 9 November 2011 Version 1.50 - 16 September 2011

Required for CryptoNite 1.1.8 and up Version 1.45 - 20 August 2011

Required for CryptoNite 1.1.8 and up Version 1.44 - 20 August 2011

Required for CryptoNite 1.1.8 and up Version 1.43 - 19 August 2011

Required for CryptoNite 1.1.8 and up Version 1.42 - 02 August 2011

Required for CryptoNite 1.1.8 and up Version 1.41 - 27 July 2011

Required for CryptoNite 1.1.8 and up Version 1.40 - 18 July 2011

Required for CryptoNite 1.1.8 and up Version 1.39 - 07 June 2011

Required for CryptoNite 1.1.8 and up Version 1.38 - 06 June 2011

Required for CryptoNite 1.1.8 and up Version 1.37 - 03 June 2011

Required for CryptoNite 1.1.8 and up Version 1.36 - 5 May 2011 Version 1.35 - 15 April 2011

Required for CryptoNite 1.15 and up Version 1.34 - 15 April 2011

Required for CryptoNite 1.15 and up Version 1.33 - 29 March 2011

Required for CryptoNite 1.12 and up
Version 1.32 - 19 January 2011

Required for CryptoNite 1.12 and up Version 1.31 - 18 January 2011

Required for CryptoNite 1.04 and up Version 1.30 - 21 December 2010

Required for CryptoNite 1.04 Version 1.29 - 10 December 2010

Required for CryptoNite 1.11 Version 1.28 - 27 November 2010 Version 1.27 - 27 October 2010

Required for CryptoNite 1.03
Version 1.26 - 15 June 2010

Required for CryptoNite 1.02 Version 1.25 - 22 September June 2010 Version 1.24 and prior (not available as a stand alone product) - 15 June 2010