Help Center
Help CenterAfxNovaString Management

String Procedures

Members (64)

AfxBase64DecodeAConverts the contents of a Base64 mime encoded string to an ascii string.AfxBase64DecodeWConverts the contents of a Base64 mime encoded string to an unicode string.AfxBase64EncodeAConverts the contents of an ascii string to Base64 mime encoding.AfxBase64EncodeWConverts the contents of an unicode string to Base64 mime encoding.AfxBase64EncodWeAAfxCryptBinaryToStringConverts an array of bytes into a formatted string.AfxCryptBinaryToStringWAfxCryptStringToBinaryConverts a formatted string into an array of bytes.AfxCryptStringToBinaryAAfxCryptStringToBinaryWAfxStrClipLeftReturns a string with the specified number of characters removed from the left side of the string.AfxStrClipMidReturns a string with the specified number of characters removed starting at the specified position.AfxStrClipRightReturns a string with the specified number of characters removed from the right side of the string.AfxStrCSetReturns a string containing a centered string.AfxStrDeleteDeletes a specified number of characters from a string expression.AfxStrExtractExtracts characters from a string up to (but not including) the specified matching. Case sensitive.AfxStrExtractAnyExtracts characters from a string up to (but not including) any character in the matching string. Case sensitive.AfxStrExtractAnyIExtracts characters from a string up to (but not including) any character in the matching string. Case insensitive.AfxStrExtractIExtracts characters from a string up to (but not including) the specified matching string. Case insensitive.AfxStrFormatByteSizeConverts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.AfxStrFormatKBSizeConverts a numeric value into a string that represents the number expressed as a size value in kilobytes.AfxStrFromTimeIntervalConverts a time interval, specified in milliseconds, to a string.AfxStrInsertInserts a string at a specified position within another string expression.AfxStrJoinReturns a string consisting of all of the strings in an array, each separated by a delimiter.AfxStrLCaseReturns a lowercased version of a string.AfxStrLSetReturns a string containing a left justified string.AfxStrParseReturns a delimited field from a string expression.AfxStrParseReturns a delimited field from a string expression.AfxStrParseAnyReturns a delimited field from a string expression. Supports more than one character for the delimiter.AfxStrParseCountReturns the count of delimited fields from a string expression.AfxStrParseCountAnyReturns the count of delimited fields from a string expression. Supports more than one character for the delimiter.AfxStrPathNameParses a path to extract component parts.AfxStrRemainReturns the portion of a string following the first occurrence of a string. Case sensitive.AfxStrRemainAnyReturns the portion of a string following the first occurrence of a group of characters. Case sensitive.AfxStrRemainAnyIReturns the portion of a string following the first occurrence of a group of characters. Case insensitive.AfxStrRemainIReturns the portion of a string following the first occurrence of a string. Case insensitive.AfxStrRemoveReturns a new string with substrings removed. Case sensitive.AfxStrRemoveAnyReturns a new string with characters removed. Case sensitive.AfxStrRemoveAnyIReturns a new string with characters removed. Case insensitive.AfxStrRemoveIReturns a new string with substrings removed. Case insensitive.AfxStrRepeatReturns a string consisting of multiple copies of the specified string.AfxStrReplaceReplaces all the occurrences of a string with another string. Case sensitive.AfxStrReplaceAnyReplaces all the occurrences of a group of characters with another character. Case sensitive.AfxStrReplaceAnyIReplaces all the occurrences of a group of characters with another character. Case insensitive.AfxStrReplaceIReplaces all the occurrences of a string with another string. Case insensitive.AfxStrRetainReturns a string containing only the characters contained in a specified match string. Case sensitive.AfxStrRetainAnyReturns a string containing only the characters contained in a specified group of characters. Case sensitive.AfxStrRetainAnyIReturns a string containing only the characters contained in a specified group of characters. Case insensitive.AfxStrRetainIReturns a string containing only the characters contained in a specified match string. Case insensitive.AfxStrReverseReverses the contents of a string expression.AfxStrRSetReturns a string containing a right justified string.AfxStrShrinkShrinks a string to use a consistent single character delimiter.AfxStrSplitSplits a string into tokens.AfxStrSpnReturns the length of the initial portion of a string which consists only of characters that are part of a specified set of characters.AfxStrTallyCount the number of occurrences of a string within a string. Case sensitive.AfxStrTallyAnyCount the number of occurrences of a list of characters within a string. Case sensitive.AfxStrTallyAnyICount the number of occurrences of a list of characters within a string. Case insensitive.AfxStrTallyICount the number of occurrences of a string within a string. Case insensitive.AfxStrUCaseReturns an uppercased version of a string.AfxStrUnWrapRemoves paired characters to the beginning and end of a string.AfxStrVerifyDetermine whether each character of a string is present in another string. Case sensitive.AfxStrVerifyIDetermine whether each character of a string is present in another string. Case insensitive.AfxStrWrapAdds paired characters to the beginning and end of a string.FUNCTION

Documentation

String Procedures

This is a collection of assorted, ready-to-use string procedures to manipulate FreeBasic strings and my own DWSTRING (Dynamic Unicode string) and BSTRING (OLE strings, aka BSTR). They were originally dessigned to work with the CWSTRdata type, which has now been superseded by DWSTRING. While all of them have replacements in DWStrProcs.inc, they have been updated to simplify the porting of applications from the Afx framework to the AfxNova framework.

Include file: AfxStr.inc

NameDescription
AfxStrClipLeftReturns a string with the specified number of characters removed from the left side of the string.
AfxStrClipMidReturns a string with the specified number of characters removed starting at the specified position.
AfxStrClipRightReturns a string with the specified number of characters removed from the right side of the string.
AfxStrCSetReturns a string containing a centered string.
AfxStrDeleteDeletes a specified number of characters from a string expression.
AfxStrExtractExtracts characters from a string up to (but not including) the specified matching. Case sensitive.
AfxStrExtractIExtracts characters from a string up to (but not including) the specified matching string. Case insensitive.
AfxStrExtractAnyExtracts characters from a string up to (but not including) any character in the matching string. Case sensitive.
AfxStrExtractAnyIExtracts characters from a string up to (but not including) any character in the matching string. Case insensitive.
AfxStrInsertInserts a string at a specified position within another string expression.
AfxStrJoinReturns a string consisting of all of the strings in an array, each separated by a delimiter.
AfxStrLCaseReturns a lowercased version of a string.
AfxStrLSetReturns a string containing a left justified string.
AfxStrParseReturns a delimited field from a string expression.
AfxStrParseAnyReturns a delimited field from a string expression. Supports more than one character for the delimiter.
AfxStrParseCountReturns the count of delimited fields from a string expression.
AfxStrParseCountAnyReturns the count of delimited fields from a string expression. Supports more than one character for the delimiter.
AfxStrRemainReturns the portion of a string following the first occurrence of a string. Case sensitive.
AfxStrRemainIReturns the portion of a string following the first occurrence of a string. Case insensitive.
AfxStrRemainAnyReturns the portion of a string following the first occurrence of a group of characters. Case sensitive.
AfxStrRemainAnyIReturns the portion of a string following the first occurrence of a group of characters. Case insensitive.
AfxStrRemoveReturns a new string with substrings removed. Case sensitive.
AfxStrRemoveIReturns a new string with substrings removed. Case insensitive.
AfxStrRemoveAnyReturns a new string with characters removed. Case sensitive.
AfxStrRemoveAnyIReturns a new string with characters removed. Case insensitive.
AfxStrRepeatReturns a string consisting of multiple copies of the specified string.
AfxStrReplaceReplaces all the occurrences of a string with another string. Case sensitive.
AfxStrReplaceIReplaces all the occurrences of a string with another string. Case insensitive.
AfxStrReplaceAnyReplaces all the occurrences of a group of characters with another character. Case sensitive.
AfxStrReplaceAnyIReplaces all the occurrences of a group of characters with another character. Case insensitive.
AfxStrRetainReturns a string containing only the characters contained in a specified match string. Case sensitive.
AfxStrRetainIReturns a string containing only the characters contained in a specified match string. Case insensitive.
AfxStrRetainAnyReturns a string containing only the characters contained in a specified group of characters. Case sensitive.
AfxStrRetainAnyIReturns a string containing only the characters contained in a specified group of characters. Case insensitive.
AfxStrReverseReverses the contents of a string expression.
AfxStrRSetReturns a string containing a right justified string.
AfxStrShrinkShrinks a string to use a consistent single character delimiter.
AfxStrSplitSplits a string into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters.
AfxStrSpnReturns the length of the initial portion of a string which consists only of characters that are part of a specified set of characters.
AfxStrTallyCount the number of occurrences of a string within a string. Case sensitive.
AfxStrTallyICount the number of occurrences of a string within a string. Case insensitive.
AfxStrTallyAnyCount the number of occurrences of a list of characters within a string. Case sensitive.
AfxStrTallyAnyICount the number of occurrences of a list of characters within a string. Case insensitive.
AfxStrUCaseReturns an uppercased version of a string.
AfxStrVerifyDetermine whether each character of a string is present in another string. Case sensitive.
AfxStrVerifyIDetermine whether each character of a string is present in another string. Case insensitive.
AfxStrWrapAdds paired characters to the beginning and end of a string.
AfxStrUnWrapRemoves paired characters to the beginning and end of a string.
AfxStrPathNameParses a path to extract component parts.
AfxStrFormatByteSizeConverts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.
AfxStrFormatKBSizeConverts a numeric value into a string that represents the number expressed as a size value in kilobytes.
AfxStrFromTimeIntervalConverts a time interval, specified in milliseconds, to a string.
AfxBase64DecodeAConverts the contents of a Base64 mime encoded string to an ascii string.
AfxBase64DecodeWConverts the contents of a Base64 mime encoded string to an unicode string.
AfxBase64EncodeAConverts the contents of an ascii string to Base64 mime encoding.
AfxBase64EncodeWConverts the contents of an unicode string to Base64 mime encoding.
AfxCryptBinaryToStringConverts an array of bytes into a formatted string.
AfxCryptStringToBinaryConverts a formatted string into an array of bytes.

AfxStrClipLeft

Returns a string with nCount characters removed from the left side of the string.

FUNCTION AfxStrClipLeft (BYREF wszMainStr AS CONST WSTRING, BYVAL nCount AS LONG) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
nCountThe number of characters to be removed.

AfxStrClipMid

Returns a string with nCount characters removed from the left side of the string.

FUNCTION AfxStrClipMid (BYREF wszMainStr AS CONST WSTRING, BYVAL nStart AS LONG, BYVAL nCount AS LONG) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
nStartThe one-based starting position.
nCountThe number of characters to be removed.

AfxStrClipRight

Returns a string with nCount characters removed from the right side of the string.

FUNCTION AfxStrClipRight  (BYREF wszMainStr AS CONST WSTRING, BYVAL nCount AS LONG) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
nCountThe number of characters to be removed.

AfxStrCSet

Returns a string containing a centered string.

FUNCTION AfxStrCSet (BYREF wszMainStr AS CONST WSTRING, _
   BYVAL nStringLength AS LONG, BYREF wszPadCharacter AS CONST WSTRING = " ") AS DWSTRING
ParameterDescription
wszMainStrThe string to be justified.
nStringLengthThe length of the new string.
wszPadCharacterThe character to be used for padding. If it is not specified, the string will be padded with spaces.
Usage example
DIM dws AS DWSTRING = AfxStrCSet("FreeBasic", 20, "*")

AfxStrDelete

Deletes a specified number of characters from a string expression.

FUNCTION AfxStrDelete (BYREF wszMainStr AS CONST WSTRING, _
   BYVAL nStart AS LONG, BYVAL nCount AS LONG) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
nStartThe one-based starting position.
nCountThe number of characters to be removed.
Usage example
DIM dws AS DWSTRING = AfxStrDelete("1234567890", 4, 3)   ' Returns 1237890"

AfxStrExtract

Extracts characters from a string up to (but not including) a string. Case sensitive.

FUNCTION AfxStrExtract (BYVAL nStart AS LONG, _
   BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
nStartThe one-based starting position.
wszMainStrThe main string.
wszMatchStrThe string to be searched.
Usage example
The following line returns "aba" (match on "cad")
DIM dws AS DWSTRING = AfxStrExtract(1, "abacadabra","cad")

AfxStrExtract (Overload)

FUNCTION AfxStrExtract (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszDelim1 AS WSTRING, BYREF wszDelim2 AS WSTRING) AS DWSTRING

Extracts the portion of a string following the occurrence of a specified delimiter up to the second delimiter. If one or both of the delimiters aren't found, it returns an empty string.

ParameterDescription
wszMainStrThe main string.
wszDelim1The first delimiter.
wszDelim2The second delimiter.
Usage example
The following lines return "text between parentheses" (text delimited by "(" and ")")
DIM dws AS DWSTRING = "blah blah (text between parentheses) blah blah"
PRINT AfxStrExtract(dws, "(", ")")

AfxStrExtract (Overload)

FUNCTION AfxStrExtract (BYVAL nStart AS LONG, BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszDelim1 AS WSTRING, BYREF wszDelim2 AS WSTRING) AS DWSTRING
ParameterDescription
nStartThe one-based starting position.
wszMainStrThe main string.
wszDelim1The first delimiter.
wszDelim2The second delimiter.

AfxStrExtractI

Extracts characters from a string up to (but not including) a string. Case insensitive.

FUNCTION AfxStrExtractI (BYVAL nStart AS LONG, _
   BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
nStartThe one-based starting position.
wszMainStrThe main string.
wszMatchStrThe string to be searched.
Usage example
The following line returns "aba" (match on "CaD")
DIM dws AS DWSTRING = AfxStrExtractI(1, "abacadabra","CaD")

AfxStrExtractAny

Extracts characters from a string up to (but not including) a group of characters. Case sensitive.

FUNCTION AfxStrExtractAny (BYVAL nStart AS LONG, _
   BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
nStartThe one-based starting position.
wszMainStrThe main string.
wszMatchStrThe characters to be searched individually. A match on any one of which will cause the extract operation to be performed up to that character.
Usage example
The following line returns "aba" (match on "c")
DIM dws AS DWSTRING = AfxStrExtractAny(1, "abacadabra","cd")

AfxStrExtractAnyI

Extracts characters from a string up to (but not including) a group of characters. Case insensitive.

FUNCTION AfxStrExtractAnyI (BYVAL nStart AS LONG, _
   BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
nStartThe one-based starting position.
wszMainStrThe main string.
wszMatchStrThe characters to be searched individually. A match on any one of which will cause the extract operation to be performed up to that character.
Usage example
The following line returns "aba" (match on "c")
DIM dws AS DWSTRING = AfxStrExtractAnyI(1, "abacadabra","Cd")

AfxStrFormatByteSize

Converts a numeric value into a string that represents the number expressed as a size value in bytes, kilobytes, megabytes, or gigabytes, depending on the size.

FUNCTION AfxStrFormatByteSize (BYVAL ull AS ULONGLONG) AS DWSTRING
ParameterDescription
ullThe numeric value to be converted.

AfxStrFormatKBSize

Converts a numeric value into a string that represents the number expressed as a size value in kilobytes.

FUNCTION AfxStrFormatKBSize (BYVAL ull AS ULONGLONG) AS DWSTRING
ParameterDescription
ullThe numeric value to be converted.

AfxStrFromTimeInterval

Converts a time interval, specified in milliseconds, to a string.

FUNCTION AfxStrFromTimeInterval (BYVAL dwTimeMS AS DWORD, BYVAL digits AS LONG) AS DWSTRING
ParameterDescription
dwTimeMSThe time interval, in milliseconds.
digitsThe maximum number of significant digits to be represented in the output string.

Some examples for digits:

dwTimeMSdigitsdwsOut
34000334 sec
34000234 sec
34000130 sec
7400031 min 14 sec
7400021 min 10 sec
7400021 min

AfxStrInsert

Inserts a string at a specified position within another string expression.

FUNCTION AfxStrInsert (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszInsertString AS CONST WSTRING, BYVAL nPosition AS LONG) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszInsertStringThe string to be inserted.
nPositionThe one-based starting position. If nPosition is greater than the length of wszMainStr or <= zero then wszInsertString is appended to wszMainStr.
Usage example
DIM dws AS DWSTRING = AfxStrInsert("1234567890", "--", 6)   ' Returns "123456--7890"

AfxStrJoin

Returns a string consisting of all of the strings in an array, each separated by a delimiter. If the delimiter is a null (zero-length) string then no separators are inserted between the string sections. If the delimiter expression is the 3-byte value of "," which may be expressed in your source code as the string literal """,""" or as Chr(34,44,34) then a leading and trailing double-quote is added to each string section. This ensures that the returned string contains standard comma-delimited quoted fields that can be easily parsed.

FUNCTION AfxStrJoin (BYREF dsa AS DSafeArray, BYREF wszDelimiter AS WSTRING = " ") AS DWSTRING
ParameterDescription
dsaThe one-dimensional VT_BSTR DSafeArray to join.
wszDelimiterThe delimiter character.
Return value

A DWSTRING containing the joined string.

Usage example
DIM dsa AS DSafeArray = DSafeArray("STRING", 3, 1)
dsa.PutStr(1, "One")
dsa.PutStr(2, "Two")
dsa.PutStr(3, "Three")
DIM dws AS DWSTRING = AfxStrJoin(csa, ",")
PRINT dws   ' ouput: One,Two,Three

Include file: DSafeArray.inc


AfxStrLCase

Returns a lowercased version of a string.

FUNCTION AfxStrLCase (BYVAL pwszStr AS WSTRING PTR, _
   BYVAL pwszLocaleName AS WSTRING PTR = LOCALE_NAME_USER_DEFAULT, _
   BYVAL dwMapFlags AS DWORD = 0) AS DWSTRING
ParameterDescription
pwszStrThe string.
pwszLocaleNameOptional. Pointer to a locale name or one of these pre-defined values: LOCALE_NAME_INVARIANT, LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_NAME_USER_DEFAULT
dwMapFlagsOptional. Flag specifying the type of transformation to use during string mapping or the type of sort key to generate.

For a table of language culture names see: Table of Language Culture Names, Codes, and ISO Values)

For a complete list see: LCMapStringEx function

Remarks

The string conversion functions available in FreeBasic are not fully suitable for some languages. For example, the Turkish word "karışıklığı" is uppercased as "KARıŞıKLıĞı" instead of "KARIŞIKLIĞI", and "KARIŞIKLIĞI" is lowercased to "karişikliği" instead of "karışıklığı". Notice the "ı", that is not an "i".

Return value

The lowercased string.


AfxStrLSet

Returns a string containing a left justified string.

FUNCTION AfxStrLSet (BYREF wszMainStr AS CONST WSTRING, _
   BYVAL nStringLength AS LONG, BYREF wszPadCharacter AS CONST WSTRING = " ") AS DWSTRING
ParameterDescription
wszMainStrThe string to be justified.
nStringLengthThe length of the new string.
wszPadCharacterThe character to be used for padding. If it is not specified, the string will be padded with spaces.
Usage example
DIM dws AS DWSTRING = AfxStrLSet("FreeBasic", 20, "*")

AfxStrParse

Returns a delimited field from a string expression.

FUNCTION AfxStrParse (BYREF wszMainStr AS CONST WSTRING, _
   BYVAL nPosition AS LONG = 1, BYREF wszDelimiter AS CONST WSTRING = ",") AS DWSTRING
ParameterDescription
wszMainStrThe string to be parsed.
nPositionStarting position. If nPosition is zero or is outside of the actual field count, an empty string is returned. If nPosition is negative, fields are searched from the right to left of the wszMainStr.
wszDelimiterA string of one or more characters that must be fully matched to be successful.
Usage example
DIM dws AS DWSTRING = AfxStrParse("one,two,three", 2)   ' Returns "two"
DIM dws AS DWSTRING = AfxStrParse("one;two,three", 1, ";")   ' Returns "one"

AfxStrParseAny

Returns a delimited field from a string expression.

FUNCTION AfxStrParse (BYREF wszMainStr AS CONST WSTRING, _
   BYVAL nPosition AS LONG = 1, BYREF wszDelimiter AS CONST WSTRING = ",") AS DWSTRING
ParameterDescription
wszMainStrThe string to be parsed.
nPositionStarting position. If nPosition is zero or is outside of the actual field count, an empty string is returned. If nPosition is negative, fields are searched from the right to left of the wszMainStr.
wszDelimiterA string of one or more characters any of which may act as a delimiter character.
Usage example
DIM dws AS DWSTRING = AfxStrParseAny("1;2,3", 2, ",;")   ' Returns "2"

AfxStrParseCount

Returns the count of delimited fields from a string expression.

FUNCTION AfxStrParseCount (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszDelimiter AS CONST WSTRING = ",") AS LONG
ParameterDescription
wszMainStrThe main string. If wszMainStr is empty (a null string) or contains no delimiter character(s), the string is considered to contain exactly one subfield.
wszDelimiterOne or more character delimiters that must be fully matched. Delimiters are case-sensitive.
Usage example
DIM nCount AS LONG = AfxStrParseCount("one,two,three", ",")   ' Returns 3

AfxStrParseCountAny

Returns the count of delimited fields from a string expression.

FUNCTION AfxStrParseCountAny (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszDelimiter AS CONST WSTRING = ",") AS LONG
ParameterDescription
wszMainStrThe main string. If wszMainStr is empty (a null string) or contains no delimiter character(s), the string is considered to contain exactly one sub-field.
wszDelimiterA set of characters (one or more), any of which may act as a delimiter character. Delimiters are case-sensitive.
Usage example
DIM nCount AS LONG = AfxStrParseCountAny("1;2,3", ",;")   ' Returns 3

AfxStrPathName

Parses a path to extract component parts.

FUNCTION AfxStrPathName (BYREF wszOption AS CONST WSTRING, BYREF wszFileSpec AS WSTRING) AS DWSTRING
ParameterDescription
wszOptionOne of the following words which is used to specify the requested part: PATH, NAME, EXTN, NAMEX.
wszFileSpecThe path to be scanned.
KeywordAction
PATHReturns the path portion of the path/file Name. That is the text up to and including the last backslash (\) or colon (:).
NAMEReturns the name portion of the path/file Name. That is the text to the right of the last backslash (\) or colon (:), ending just before the last period (.).
EXTNReturns the extension portion of the path/file name. That is the last period (.) in the string plus the text to the right of it.
NAMEXReturns the name and the extension parts combined.

AfxStrRemain

Returns the portion of a string following the first occurrence of a string. Case sensitive.

FUNCTION AfxStrRemain (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYVAL nStart AS LONG = 1) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string to search for.
nStartOptional. Starting position to begin the search. If nStart is not specified, the search will begin at position 1. If nStart is zero, a nul string is returned. If nStart is negative, the starting position is counted from right to left: -1 for the last character, -2 for the second to last, etc.
Usage example
DIM dws AS DWSTRING = AfxStrRemain("Brevity is the soul of wit", "is ")   ' Returns "the soul of wit"

AfxStrRemainI

Returns the portion of a string following the first occurrence of a string. Case insensitive.

FUNCTION AfxStrRemainI (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYVAL nStart AS LONG = 1) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string to search for.
nStartOptional. starting position to begin the search. If nStart is not specified, the search will begin at position 1. If nStart is zero, a nul string is returned. If nStart is negative, the starting position is counted from right to left: -1 for the last character, -2 for the second to last, etc.
Usage example
DIM dws AS DWSTRING = AfxStrRemain("Brevity is the soul of wit", "Is ")   ' Returns "the soul of wit"

AfxStrRemainAny

Returns the portion of a string following the first occurrence of a list of characters. Case sensitive.

FUNCTION AfxStrRemainAny (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYVAL nStart AS LONG = 1) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe characters to search for.
nStartOptional. starting position to begin the search. If nStart is not specified, the search will begin at position 1. If nStart is zero, a nul string is returned. If nStart is negative, the starting position is counted from right to left: -1 for the last character, -2 for the second to last, etc.
Usage example
DIM dws AS DWSTRING = AfxStrRemainAny("I think, therefore I am", ",")   ' Returns " therefore I am"

AfxStrRemainAnyI

Returns the portion of a string following the first occurrence of a list of characters. Case insensitive.

FUNCTION AfxStrRemainAnyI (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYVAL nStart AS LONG = 1) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe characters to search for.
nStartOptional. starting position to begin the search. If nStart is not specified, the search will begin at position 1. If nStart is zero, a nul string is returned. If nStart is negative, the starting position is counted from right to left: -1 for the last character, -2 for the second to last, etc.
Usage example
DIM dws AS DWSTRING = AfxStrRemainAnyI("I think, therefore I am", "E")   ' -> "refore I am"

AfxStrRemove

Returns a new string with strings removed. Case sensitive.

FUNCTION AfxStrRemove (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be removed. If wszMatchStr is not present in wszMainStr, all of wszMainStr is returned intact.
Usage example
DIM dws AS DWSTRING = AfxStrRemove("Hello World. Welcome to the Freebasic World", "World")

AfxStrRemove (Overload)

Returns a copy of a string with a substring enclosed between the specified delimiters removed. Case sensitive.

FUNCTION AfxStrRemove (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszDelim1 AS CONST WSTRING, BYREF wszDelim2 AS CONST WSTRING, _
   BYVAL fRemoveAll AS BOOLEAN = FALSE) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszDelim1The first delimiter
wszDelim2The second delimiter
fRemoveAllRecursively remove all the occurrences.
Usage examples
DIM dwsText AS DWSTRING = "blah blah (text between parentheses) blah blah"
DIM dws AS DWSTRING = AfxStrRemove(dwsText, "(", ")")   ' Returns "blah blah  blah blah"
DIM dwsText AS DWSTRING = "As Long var1(34), var2(  73 ), var3(any)"
DIM dws AS DWSTRING = AfxStrRemove(dwsText, "(", ")", TRUE)   ' Returns "As Long var1, var2, var3"

AfxStrRemove (Overload)

Returns a copy of a string with a substring enclosed between the specified delimiters removed. Case sensitive.

FUNCTION AfxStrRemove (BYVAL nStart AS LONG = 1, BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszDelim1 AS CONST WSTRING, BYREF wszDelim2 AS CONST WSTRING, _
   BYVAL fRemoveAll AS BOOLEAN = FALSE) AS DWSTRING
ParameterDescription
nStartOptional. The one-based starting position where to start the search.
wszMainStrThe main string.
wszDelim1The first delimiter
wszDelim2The second delimiter
fRemoveAllRecursively remove all the occurrences.
Usage examples
DIM dwsText AS DWSTRING = "blah blah (text beween parentheses) blah blah"
DIM dws AS DWSTRING = AfxStrRemove(dwsText, "(", ")")   ' Returns "blah blah  blah blah"

AfxStrRemoveI

Returns a new string with strings removed. Case insensitive.

FUNCTION AfxStrRemoveI (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be removed. If wszMatchStr is not present in wszMainStr, all of wszMainStr is returned intact.
Usage example
AfxStrRemoveI("Hello World. Welcome to the Freebasic World", "world")

AfxStrRemoveAny

Returns a new string with characters removed. Case sensitive.

FUNCTION AfxStrRemoveAny (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be removed. If wszMatchStr is not present in wszMainStr, all of wszMainStr is returned intact.
Usage example
DIM dws AS DWSTRING = AfxStrRemoveAny("abacadabra", "bac")   ' -> "dr"

AfxStrRemoveAnyI

Returns a new string with characters removed. Case insensitive.

FUNCTION AfxStrRemoveAnyI (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be removed. If wszMatchStr is not present in wszMainStr, all of wszMainStr is returned intact.
Usage example
DIM dws AS DWSTRING = AfxStrRemoveAnyI("abacadabra", "BaC")   ' -> "dr"

AfxStrRepeat

Returns a string consisting of multiple copies of the specified string. This function is similar to STRING, but STRING only makes multiple copies of a single character.

FUNCTION AfxStrRepeat (BYVAL nCount AS LONG, BYREF wszStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
nCountThe number of copies.
wszStrThe string to be copied.
Usage example
DIM dws AS DWSTRING = AfxStrRepeat(5, "Paul")

AfxStrReplace

Replaces all the occurrences of wszMatchStr in wszMainstr with the contents of wszReplaceWith. Case sensitive.

FUNCTION AfxStrReplace (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYREF wszReplaceWith AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified string.
wszMatchStrThe string expression to be replaced.
wszReplaceWithThe replacement string.
Usage example
DIM dws AS DWSTRING = AfxStrReplace("Hello World", "World", "Earth")   ' Returns "Hello Earth"

AfxStrReplaceI

Replaces all the occurrences of wszMatchStr in wszMainstr with the contents of wszReplaceWith. Case insensitive.

FUNCTION AfxStrReplaceI (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYREF wszReplaceWith AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified string.
wszMatchStrThe string expression to be replaced.
wszReplaceWithThe replacement string.
Usage example
DIM dws AS DWSTRING = AfxStrReplaceI("Hello world", "World", "Earth")   ' -> "Hello Earth"

AfxStrReplaceAny

Replaces all the occurrences of any of the individual characters wszMatchStr in wszMainstr with the contents of wszReplaceWith. wszReplaceWith must be a single character (this function does not replace words; therefore, wszMatchStr will not shrink or grow). Case sensitive.

FUNCTION AfxStrReplaceAny  (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYREF wszReplaceWith AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified characters.
wszMatchStrThe characters to be replaced.
wszReplaceWithThe replacement character.
Usage example
DIM dws AS DWSTRING = AfxStrReplaceAny("abacadabra", "bac", "*")   ' -> *****d**r*

AfxStrReplaceAnyI

Replaces all the occurrences of any of the individual characters wszMatchStr in wszMainstr with the contents of wszReplaceWith. wszReplaceWith must be a single character (this function does not replace words; therefore, wszMatchStr will not shrink or grow). Case insensitive.

FUNCTION AfxStrReplaceAnyI  (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszMatchStr AS CONST WSTRING, BYREF wszReplaceWith AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified characters.
wszMatchStrThe characters to be replaced.
wszReplaceWithThe replacement character.
Usage example
DIM dws AS DWSTRING = AfxStrReplaceAnyI("abacadabra", "BaC", "*")   ' -> *****d**r*

AfxStrRetain

Returns a string containing only the characters contained in a specified match string. Case sensitive.

FUNCTION AfxStrRetain (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified string.
wszMatchStrThe string expression to be searched.
Usage example
DIM dws AS DWSTRING = AfxStrRetain("abacadabra","b")   ' -> "bb"

AfxStrRetainI

Returns a string containing only the characters contained in a specified match string. Case insensitive.

FUNCTION AfxStrRetainI (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified string.
wszMatchStrThe string expression to be searched.
Usage example
DIM dws AS DWSTRING = AfxStrRetainI("abacadabra","B")   ' -> "bb"

AfxStrRetainAny

Returns a string containing only the characters contained in a specified group of characters. Case sensitive.

FUNCTION AfxStrRetainAny (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified string.
wszMatchStrA list of single characters to be searched for individually. A match on any one of which will cause that character to be removed from the result.
Usage example
DIM dws AS DWSTRING = AfxStrRetainAny("<p>1234567890<ak;lk;l>1234567890</p>", "<;/p>")

AfxStrRetainAnyI

Returns a string containing only the characters contained in a specified group of characters. Case insensitive.

FUNCTION AfxStrRetainAnyI (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string from which you want to replace the specified string.
wszMatchStrA list of single characters to be searched for individually. A match on any one of which will cause that character to be removed from the result.
Usage example
DIM dws AS DWSTRING = AfxStrRetainAnyI("<p>1234567890<ak;lk;l>1234567890</p>", "<;/P>")

AfxStrReverse

Reverses the contents of a string expression.

FUNCTION AfxStrReverse (BYREF wszMainStr AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe string to be reversed.
Usage example
DIM dws AS DWSTRING = AfxStrReverse("garden")   ' Returns "nedrag"

AfxStrRSet

Returns a string containing a right justified string.

FUNCTION AfxStrRSet (BYREF wszMainStr AS CONST WSTRING, _
   BYVAL nStringLength AS LONG, BYREF wszPadCharacter AS CONST WSTRING = " ") AS DWSTRING
ParameterDescription
wszMainStrThe string to be justified.
nStringLengthThe length of the new string.
wszPadCharacterThe character to be used for padding. If it is not specified, the string will be padded with spaces.
Usage example
DIM dws AS DWSTRING = AfxStrRSet("FreeBasic", 20, "*")

AfxStrShrink

Shrinks a string to use a consistent single character delimiter.

FUNCTION AfxStrShrink (BYREF wszMainStr AS CONST WSTRING, BYREF wszMask AS CONST WSTRING = " ") AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszMaskOne or more character delimiters to shrink.
Remarks

This function creates a string with consecutive words separated by a consistent single character, making it easier to parse. If wszMask is not specified, all leading and trailing spaces are removed and all occurrences of two or more spaces are changed to a single space. If wszMask contains one or more characters to shrink, all the leading and trailing occurences of them are removes and all occurrences of one or more characters of the mask are replaced with the first character of the mask.

Usage example
DIM dws AS DWSTRING = AfxStrShrink(",,, one , two     three, four,", " ,")  ' Returns "one two three four"

AfxStrSplit

Splits a string into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters.

FUNCTION AfxStrSplit (BYREF wszStr AS CONST WSTRING, BYREF wszDelimiters AS WSTRING = " ") AS DSafeArray
ParameterDescription
wszStrThe string to split.
wszDelimitersThe delimiter characters.
Return value

A DSafeArray containing a token in each element.

Usage example
DIM dws AS DWSTRING = "- This, a sample string."
DIM dsa AS DSafeArray = AfxStrSplit(cws, " ,.-")
FOR i AS LONG = dsa.LBound TO dsa.UBound
  PRINT dsa.GetStr(i)
NEXT

Include file: DSafeArray.inc


AfxStrSpn

Returns the length of the initial portion of a string which consists only of characters that are part of a specified set of characters.

FUNCTION AfxStrSpn (BYREF wszText AS CONST WSTRING, BYREF wszSet AS CONST WSTRING) AS LONG
ParameterDescription
wszTextThe string to be scanned.
wszSetThe set of characters for which to search.
Usage example
DIM wszText AS WSTRING * 260 = "129th"
DIM wszSet AS WSTRING * 260 = "1234567890"
DIM n AS LONG = StrSpnW(@wszText, @wszSet)
printf(!"The initial number has %d digits.\n", n)

AfxStrTally

Count the number of occurrences of a string or a list of characters within a string. Case sensitive.

FUNCTION AfxStrTally (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS LONG
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be searched.
Return value

The number of occurrences of wszMatchStr in wszMainStr.

Usage example
DIM nCount AS LONG = AfxStrTally("abacadabra", "ab")   ' Returns 2

AfxStrTallyI

Count the number of occurrences of a string or a list of characters within a string. Case insensitive.

FUNCTION AfxStrTallyI (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS LONG
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be searched.
Return value

The number of occurrences of wszMatchStr in wszMainStr.

Usage example
DIM nCount AS LONG = AfxStrTallyI("abacadabra", "Ab")   ' -> 2

AfxStrTallyAny

Count the number of occurrences of a string or a list of characters within a string. Case sensitive.

FUNCTION AfxStrTallyAny (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS LONG
ParameterDescription
wszMainStrThe main string.
wszMatchStrA list of single characters to be searched for individually. A match on any one of which will cause the count to be incremented for each occurrence of that character. Note that repeated characters in wszMatchStr will not increase the count.
Return value

The number of occurrences of wszMatchStr in wszMainStr.

Usage example
DIM nCount AS LONG = AfxStrTallyAny("abacadabra", "bac")   ' -> 8

AfxStrTallyAnyI

Count the number of occurrences of a string or a list of characters within a string. Case insensitive.

FUNCTION AfxStrTallyAnyI (BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS LONG
ParameterDescription
wszMainStrThe main string.
wszMatchStrA list of single characters to be searched for individually. A match on any one of which will cause the count to be incremented for each occurrence of that character. Note that repeated characters in wszMatchStr will not increase the count.
Return value

The number of occurrences of wszMatchStr in wszMainStr.

Usage example
DIM nCount AS LONG = AfxStrTallyAnyI("abacadabra", "bAc")   ' -> 8

AfxStrUCase

Returns an uppercased version of a string.

FUNCTION AfxStrUCase (BYVAL pwszStr AS WSTRING PTR, _
   BYVAL pwszLocaleName AS WSTRING PTR = LOCALE_NAME_USER_DEFAULT, _
   BYVAL dwMapFlags AS DWORD = 0) AS DWSTRING
ParameterDescription
pwszStrThe main string.
pwszLocaleNameOptional. Pointer to a locale name or one of these pre-defined values: LOCALE_NAME_INVARIANT, LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_NAME_USER_DEFAULT
dwMapFlagsOptional. Flag specifying the type of transformation to use during string mapping or the type of sort key to generate.

For a table of language culture names see: Table of Language Culture Names, Codes, and ISO Values)

For a complete list see: LCMapStringEx function

Remarks

The string conversion functions available in FreeBasic are not fully suitable for some languages. For example, the Turkish word "karışıklığı" is uppercased as "KARıŞıKLıĞı" instead of "KARIŞIKLIĞI", and "KARIŞIKLIĞI" is lowercased to "karişikliği" instead of "karışıklığı". Notice the "ı", that is not an "i".

For Turkey, use: AfxStrUcase("karışıklığı", "tr-TR") AfxStrLCase("KARIŞIKLIĞI", "tr-TR")

Return value

The uppercased string.


AfxStrUnWrap

Removes paired characters to the beginning and end of a string.

FUNCTION AfxStrUnWrap (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszLeftChar AS CONST WSTRING, BYREF wszRightChar AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszLeftCharThe left character.
wszRightCharThe right character.
FUNCTION AfxStrUnWrap (BYREF wszMainStr AS CONST WSTRING, BYREF wszChar AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszCharThe same character for both the left and right sides.
Remarks

If only one wrap character/string is specified then that character or string is used for both sides. If no wrap character/string is specified then double quotes are used.

Usage examples
AfxStrUnWrap("<Paul>", "<", ">") results in Paul
AfxStrUnWrap("'Paul'", "'") results in Paul
AfxStrUnWrap("""Paul""") results in Paul

AfxStrVerify

Determine whether each character of a string is present in another string. Case sensitive.

FUNCTION AfxStrVerify (BYVAL nStart AS LONG, _
   BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS LONG
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be searched.
Return value

Returns zero if each character in wszMainStr is present in wszMatchStr; otherwise, it returns the position of the first non-matching character in wszMainStr. If nStart is zero, a negative number of a value greater that the length of wszMainstr, zero is returned.

Usage example
DIM nCount AS LONG = AfxStrVerify(5, "123.65,22.5", "0123456789")   ' Returns 7
Remark

Returns 7 since 5 starts it past the first non-digit "." at position 4.


AfxStrVerifyI

Determine whether each character of a string is present in another string. Case insensitive.

FUNCTION AfxStrVerifyI (BYVAL nStart AS LONG, _
   BYREF wszMainStr AS CONST WSTRING, BYREF wszMatchStr AS CONST WSTRING) AS LONG
ParameterDescription
wszMainStrThe main string.
wszMatchStrThe string expression to be searched.
Return value

Returns zero if each character in wszMainStr is present in wszMatchStr; otherwise, it returns the position of the first non-matching character in wszMainStr. If nStart is zero, a negative number of a value greater that the length of wszMainstr, zero is returned.

Usage example
DIM nCount AS LONG = AfxStrVerifyI(5, "123.65abcx22.5", "0123456789ABC")   ' -> 10

AfxStrWrap

Adds paired characters to the beginning and end of a string.

FUNCTION AfxStrWrap (BYREF wszMainStr AS CONST WSTRING, _
   BYREF wszLeftChar AS CONST WSTRING, BYREF wszRightChar AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszLeftCharThe left character.
wszRightCharThe right character.
FUNCTION AfxStrWrap (BYREF wszMainStr AS CONST WSTRING, BYREF wszChar AS CONST WSTRING) AS DWSTRING
ParameterDescription
wszMainStrThe main string.
wszCharThe same character for both the left and right sides.
Remarks

If only one wrap character/string is specified then that character or string is used for both sides. If no wrap character/string is specified then double quotes are used.

Usage examples
AfxStrWrap("Paul", "<", ">") results in <Paul>
AfxStrWrap("Paul", "'") results in 'Paul'
AfxStrWrap("Paul") results in "Paul"

AfxBase64DecodeA

Converts the contents of a Base64 mime encoded string to an ascii string.

FUNCTION AfxBase64DecodeA (BYREF strData AS STRING) AS STRING
ParameterDescription
strDataThe string to decode.
Return value

The decoded string on success, or a null string on failure.

Remaks

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is used commonly in a number of applications including email via MIME, and storing complex data in XML.

If we want to encode a unicode string, we must convert it to utf8 before calling AfxBase64EncodeA, e.g.

DIM dws AS DWSTRING = "おはようございます – Good morning!"
DIM s AS STRING = AfxBase64EncodeA(dws.Utf8)

To decode it, we can use

DIM dwsOut AS DWSTRING = DWSTRING(AfxBase64DecodeA(s), CP_UTF8)

or

DIM dwsOut AS DWSTRING
dws.utf8 = AfxBase64DecodeA(s)

AfxBase64DecodeW

Converts the contents of a Base64 mime encoded string to an unicode string.

FUNCTION AfxBase64DecodeW (BYREF dwsData AS DWSTRING) AS DWSTRING
ParameterDescription
dwsDataThe string to decode.
Return value

The decoded string on success, or a null string on failure.

Remaks

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is used commonly in a number of applications including email via MIME, and storing complex data in XML.


AfxBase64EncodeA

Converts the contents of an ascii string to Base64 mime encoding.

FUNCTION AfxBase64EncodeA (BYREF strData AS STRING) AS STRING
ParameterDescription
strDataThe string to encode.
Return value

The encoded string on succeess, or a null string on failure.

Remarks

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is used commonly in a number of applications including email via MIME, and storing complex data in XML.

If we want to encode a unicode string, we must convert it to utf8 before calling AfxBase64Encode, e.g.

DIM dws AS DWSTRING = "おはようございます – Good morning!"
DIM s AS STRING = AfxBase64EncodeA(dws.Utf8)

To decode it, we can use

DIM dwsOut AS DWSTRING = DWSTRING(AfxBase64DecodeA(s), CP_UTF8)

or

DIM dwsOut AS DWSTRING
dws.utf8 = AfxBase64DecodeA(s)

AfxBase64EncodeW

Converts the contents of an unicode string to Base64 mime encoding.

FUNCTION AfxBase64EncodWeA (BYREF dwsData AS DWSTRING) AS DWSTRING
ParameterDescription
dwsDataThe string to encode.
Return value

The encoded string on succeess, or a null string on failure.

Remarks

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is used commonly in a number of applications including email via MIME, and storing complex data in XML.


AfxCryptBinaryToString

Converts an array of bytes into a formatted string.

FUNCTION FUNCTION AfxCryptBinaryToStringA ( _
   BYVAL pbBinary AS CONST UBYTE PTR, _
   BYVAL cbBinary AS DWORD, _
   BYVAL dwFlags AS DWORD, _
   BYVAL pszString AS LPSTR, _
   BYVAL pcchString AS DWORD PTR _
) AS WINBOOL
FUNCTION AfxCryptBinaryToStringW ( _
   BYVAL pbBinary AS CONST UBYTE PTR, _
   BYVAL cbBinary AS DWORD, _
   BYVAL dwFlags AS DWORD, _
   BYVAL pszString AS LPWSTR, _
   BYVAL pcchString AS DWORD PTR _
) AS WINBOOL
ParameterDescription
pbBinaryA pointer to the array of bytes to be converted into a string.
cbBinaryThe number of elements in the pbBinary array.
dwFlagsSpecifies the format of the resulting formatted string.
pszStringA pointer to a buffer that receives the converted string. To calculate the number of characters that must be allocated to hold the returned string, set this parameter to NULL. The function will place the required number of characters, including the terminating NULL character, in the value pointed to by pcchString.
pcchStringA pointer to a DWORD variable that contains the size, in characters, of the pszString buffer. If pszString is NULL, the function calculates the length of the return string (including the terminating null character) in characters and returns it in this parameter. If pszString is not NULL and big enough, the function converts the binary data into a specified string format including the terminating null character, but pcchString receives the length in characters, not including the terminating null character.

Values available for the dwFlags parameter:

ValueMeaning
CRYPT_STRING_BASE64HEADERBase64, with certificate beginning and ending headers.
CRYPT_STRING_BASE64Base64, without headers.
CRYPT_STRING_BINARYPure binary copy.
CRYPT_STRING_BASE64REQUESTHEADERBase64, with request beginning and ending headers.
CRYPT_STRING_HEXHexadecimal only.
CRYPT_STRING_HEXASCIIHexadecimal, with ASCII character display.
CRYPT_STRING_BASE64X509CRLHEADERBase64, with X.509 CRL beginning and ending headers.
CRYPT_STRING_HEXADDRHexadecimal, with address display.
CRYPT_STRING_HEXASCIIADDRHexadecimal, with ASCII character and address display.
CRYPT_STRING_HEXRAWA raw hexadecimal string. Not supported in Windows Server 2003 and Windows XP.
CRYPT_STRING_STRICTEnforce strict decoding of ASN.1 text formats. Some ASN.1 binary BLOBS can have the first few bytes of the BLOB incorrectly interpreted as Base64 text. In this case, the rest of the text is ignored. Use this flag to enforce complete decoding of the BLOB. Not suported in Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP.

In addition to the values above, one or more of the following values can be specified to modify the behavior of the function.

ValueMeaning
CRYPT_STRING_NOCRLFDo not append any new line characters to the encoded string. The default behavior is to use a carriage return/line feed (CR/LF) pair (0x0D/0x0A) to represent a new line. Not supported in Windows Server 2003 and Windows XP.
CRYPT_STRING_NOCROnly use the line feed (LF) character (0x0A) for a new line. The default behavior is to use a CR/LF pair (0x0D/0x0A) to represent a new line.
Return value

If the function succeeds, the function returns nonzero (CTRUE). If the function fails, it returns zero (FALSE).

Remarks

With the exception of when CRYPT_STRING_BINARY encoding is used, all strings are appended with a new line sequence. By default, the new line sequence is a CR/LF pair (0x0D/0x0A). If the dwFlags parameter contains the CRYPT_STRING_NOCR flag, then the new line sequence is a LF character (0x0A). If the dwFlags parameter contains the CRYPT_STRING_NOCRLF flag, then no new line sequence is appended to the string.


AfxCryptStringToBinary

Converts a formatted string into an array of bytes.

FUNCTION AfxCryptStringToBinaryA ( _
   BYVAL pszString AS LPCSTR, _
   BYVAL cchString AS DWORD, _
   BYVAL dwFlags AS DWORD, _
   BYVAL pbBinary AS UBYTE PTR, _
   BYVAL pcbBinary AS DWORD PTR, _
   BYVAL pdwSkip AS DWORD PTR, _
   BYVAL pdwFlags AS DWORD PTR _
) AS WINBOOL
FUNCTION AfxCryptStringToBinaryW ( _
   BYVAL pszString AS LPDWSTRING, _
   BYVAL cchString AS DWORD, _
   BYVAL dwFlags AS DWORD, _
   BYVAL pbBinary AS UBYTE PTR, _
   BYVAL pcbBinary AS DWORD PTR, _
   BYVAL pdwSkip AS DWORD PTR, _
   BYVAL pdwFlags AS DWORD PTR _
) AS WINBOOL
ParameterDescription
pszStringA pointer to a string that contains the formatted string to be converted.
cchStringThe number of characters of the formatted string to be converted, not including the terminating NULL character. If this parameter is zero, pszString is considered to be a null-terminated string.
dwFlagsIndicates the format of the string to be converted.
pbBinaryA pointer to a buffer that receives the returned sequence of bytes. If this parameter is NULL, the function calculates the length of the buffer needed and returns the size, in bytes, of required memory in the DWORD pointed to by pcbBinary.
pcbBinaryA pointer to a DWORD variable that, on entry, contains the size, in bytes, of the pbBinary buffer. After the function returns, this variable contains the number of bytes copied to the buffer. If this value is not large enough to contain all of the data, the function fails and GetLastError returns ERROR_MORE_DATA. If pbBinary is NULL, the DWORD pointed to by pcbBinary is ignored.
pdwSkipA pointer to a DWORD value that receives the number of characters skipped to reach the beginning of the actual base64 or hexadecimal strings. This parameter is optional and can be NULL if it is not needed.
pdwFlagsA pointer to a DWORD value that receives the flags actually used in the conversion. These are the same flags used for the dwFlags parameter. In many cases, these will be the same flags that were passed in the dwFlags parameter. If dwFlags contains one of the flags inicated below, this value will receive a flag that indicates the actual format of the string. This parameter is optional and can be NULL if it is not needed.

Values available for the dwFlags parameter:

ValueMeaning
CRYPT_STRING_BASE64HEADERBase64, with certificate beginning and ending headers.
CRYPT_STRING_BASE64Base64, without headers.
CRYPT_STRING_BINARYPure binary copy.
CRYPT_STRING_BASE64REQUESTHEADERBase64, with request beginning and ending headers.
CRYPT_STRING_BASE64Base64, without headers.
CRYPT_STRING_HEXHexadecimal only.
CRYPT_STRING_HEXASCIIHexadecimal, with ASCII character display.
CRYPT_STRING_BASE64_ANYTries the following, in order: CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64.
CRYPT_STRING_ANYTries the following, in order: CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64, CRYPT_STRING_BINARY.
CRYPT_STRING_HEX_ANYTries the following, in order: CRYPT_STRING_HEXADDR, CRYPT_STRING_HEXASCIIADDR, CRYPT_STRING_HEX, CRYPT_STRING_HEXRAW, CRYPT_STRING_HEXASCII.
CRYPT_STRING_HEXHexadecimal only.
CRYPT_STRING_BASE64X509CRLHEADERBase64, with X.509 CRL beginning and ending headers.
CRYPT_STRING_HEXADDRHexadecimal, with address display.
CRYPT_STRING_HEXASCIIADDRHexadecimal, with ASCII character and address display.
CRYPT_STRING_HEXRAWA raw hexadecimal string. Not supported in Windows Server 2003 and Windows XP.
CRYPT_STRING_STRICTEnforce strict decoding of ASN.1 text formats. Some ASN.1 binary BLOBS can have the first few bytes of the BLOB incorrectly interpreted as Base64 text. In this case, the rest of the text is ignored. Use this flag to enforce complete decoding of the BLOB. Not suported in Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP.

Values available for the pdwFlags parameter:

ValueMeaning
CRYPT_STRING_ANYThis variable will receive one of the following values. Each value indicates the actual format of the string. CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64, CRYPT_STRING_BINARY.
CRYPT_STRING_BASE64_ANYThis variable will receive one of the following values. Each value indicates the actual format of the string. CRYPT_STRING_BASE64HEADER, CRYPT_STRING_BASE64.
CRYPT_STRING_HEX_ANYThis variable will receive one of the following values. Each value indicates the actual format of the string. CRYPT_STRING_HEXADDR, CRYPT_STRING_HEXASCIIADDR, CRYPT_STRING_HEX, CRYPT_STRING_HEXRAW, CRYPT_STRING_HEXASCII.