Difference between revisions of "String Manipulation Functions"

From Flowcode Help
Jump to navigationJump to search
Line 1: Line 1:
 
<sidebar>Sidebar: Flowcode Help Overview:Functions</sidebar>
 
<sidebar>Sidebar: Flowcode Help Overview:Functions</sidebar>
 
:''See [[Calculation Icon Properties]]''
 
:''See [[Calculation Icon Properties]]''
 +
 +
__TOC__
 +
 +
==String Functions==
  
 
The String functions are a set of string manipulation functions that can be used to edit, change and examine the strings.
 
The String functions are a set of string manipulation functions that can be used to edit, change and examine the strings.
Line 6: Line 10:
 
To add a function, drag it into the calculation box. The user can then edit this base code with the variables required.
 
To add a function, drag it into the calculation box. The user can then edit this base code with the variables required.
  
 +
 +
 +
===Concatenation===
  
 
Example Strings used in explaining the functions below:
 
Example Strings used in explaining the functions below:
Line 41: Line 48:
 
TestStr is now "Hello World"
 
TestStr is now "Hello World"
  
 +
 +
 +
===Converting a numeric value/variable to a string===
  
 
'''ToString$(value)'''  
 
'''ToString$(value)'''  
Line 52: Line 62:
 
TestStr is now "1234"
 
TestStr is now "1234"
  
 +
 +
 +
===Converting a string to upper case===
  
 
'''ToUpper$(string)'''  
 
'''ToUpper$(string)'''  
Line 63: Line 76:
 
TestStr is now "HELLO "
 
TestStr is now "HELLO "
  
 +
 +
 +
===Converting a string to lower case===
  
 
'''ToLower$(string)'''  
 
'''ToLower$(string)'''  
Line 74: Line 90:
 
TestStr is now "hello "
 
TestStr is now "hello "
  
 +
 +
 +
===Finding the length of a string===
  
 
'''Length$(string)'''  
 
'''Length$(string)'''  
Line 90: Line 109:
 
Note: Str1 array size is 20, but has a String of only 6 characters currently assigned to it hence the return value of 6.
 
Note: Str1 array size is 20, but has a String of only 6 characters currently assigned to it hence the return value of 6.
  
 +
 +
 +
===String subset - characters from the start of the string===
  
 
'''Left$(string, size)'''  
 
'''Left$(string, size)'''  
Line 102: Line 124:
 
TestStr is now "Hel"
 
TestStr is now "Hel"
  
 +
 +
 +
===String subset - characters from the end of the string===
  
 
'''Right$(string, size)'''  
 
'''Right$(string, size)'''  
Line 117: Line 142:
 
TestStr is now "lo "
 
TestStr is now "lo "
  
 +
 +
 +
 +
===String subset - characters from an arbitrary position in the string===
  
 
'''Mid$(string, start, size)'''  
 
'''Mid$(string, start, size)'''  
Line 130: Line 159:
 
TestStr is now "llo"
 
TestStr is now "llo"
  
 +
 +
 +
 +
===String comparisons===
  
 
'''Compare$(string1, string2, compare_type)'''  
 
'''Compare$(string1, string2, compare_type)'''  
Line 176: Line 209:
 
RetVal is now 0 as both strings are identical.
 
RetVal is now 0 as both strings are identical.
  
 +
 +
 +
 +
===Converting a floating point value/variable to a string===
  
 
'''FloatToString$( float )'''
 
'''FloatToString$( float )'''
Line 189: Line 226:
 
string = FloatToString( float )
 
string = FloatToString( float )
  
 +
 +
 +
===Converting a numeric value/variable to a hex string===
  
 
'''NumberToHex$( number )'''
 
'''NumberToHex$( number )'''
Line 202: Line 242:
 
string = FloatToString( INT )
 
string = FloatToString( INT )
  
 +
 +
 +
===Converting a string to a numeric value/variable===
  
 
'''StringToInt$(string)'''
 
'''StringToInt$(string)'''
Line 215: Line 258:
 
number = StringToInt$( string )  
 
number = StringToInt$( string )  
  
 +
 +
 +
===Converting a string into a floating point value/variable===
  
 
'''StringToFloat$( string )'''
 
'''StringToFloat$( string )'''

Revision as of 11:17, 1 September 2014

<sidebar>Sidebar: Flowcode Help Overview:Functions</sidebar>

See Calculation Icon Properties

String Functions

The String functions are a set of string manipulation functions that can be used to edit, change and examine the strings.

To add a function, drag it into the calculation box. The user can then edit this base code with the variables required.


Concatenation

Example Strings used in explaining the functions below:

Str1[20] = "Hello "

Str2[10] = "World"

TestStr[20]


=

Changes the string to the string given. If the array.

If the string is longer than the array size then any extra characters are lost.


TestStr = Str1 + Str2


TestStr is now "Hello World"


+

Concatenates the two string together in the order presented from left to right.

If the resulting string is longer than the array size of the receiving string then any extra characters are lost.


TestStr = Str1 + Str2


TestStr is now "Hello World"


Converting a numeric value/variable to a string

ToString$(value)

Changes the numeric value to a String.


TestStr = ToStr$(1234)


TestStr is now "1234"


Converting a string to upper case

ToUpper$(string)

Changes all letters to upper case.


TestStr = ToUpper$(Str1)


TestStr is now "HELLO "


Converting a string to lower case

ToLower$(string)

Changes all letters to lower case.


TestStr = ToLower$(Str1)


TestStr is now "hello "


Finding the length of a string

Length$(string)

Retrieves the length of the string.

This is not the Array size, but the number of characters in the array before a Null character is encountered.


RetVal = Length$(Str1)


RetVal is now 6


Note: Str1 array size is 20, but has a String of only 6 characters currently assigned to it hence the return value of 6.


String subset - characters from the start of the string

Left$(string, size) Retrieves a substring from the string of size characters starting from the leftmost character.

If the length of the string used to store the result is less than size of the substring returned then any extra characters are lost.


TestStr = Left$(Str1, 3)


TestStr is now "Hel"


String subset - characters from the end of the string

Right$(string, size)

Retrieves a substring from the string of size characters starting from the rightmost character.

i.e. a size of 4 retrieves the 4 rightmost characters.

If the length of the string used to store the result is less than size of the substring returned then any extra characters are lost.


TestStr = Right$(Str1, 3)


TestStr is now "lo "



String subset - characters from an arbitrary position in the string

Mid$(string, start, size)

Retrieves a substring from the string starting at position start of size characters.

If the length of the string used to store the result is less than size of the substring returned then any extra characters are lost.


TestStr = Mid$(Str1, 2, 3)


TestStr is now "llo"



String comparisons

Compare$(string1, string2, compare_type)

Compares the two strings, parameters 1 and 2, and returns a BYTE value corresponding to the following results:


0 = strings are identical

1 = string1>string2

255 = string2>string1


The 3rd parameter, compare_type, determines whether or not the check is case sensitive. values for compare_type are:

0 = case sensitive

1 = case insensitive.

Examples


Str1 = "ABC"

Str2 = "abc"


RetVal = Compare$(Str1, Str2, 0)


RetVal is now 255 as Str2 is later in the ASCII sequence.


RetVal = Compare$(Str1, Str2, 1)


RetVal is now 0 as when case insensitive the two strings are identical.


Str2 = Str1

RetVal = Compare$(Str1, Str2, 0)


RetVal is now 0 as both strings are identical.



Converting a floating point value/variable to a string

FloatToString$( float )

Converts a floating point number into a string.


float = Floating point number to convert.

string = String variable to hold the conversion data.


string = FloatToString( float )


Converting a numeric value/variable to a hex string

NumberToHex$( number )

Converts a byte or int number into a hexadecimal string.


number = byte or integer number to convert.

string = String variable to hold the conversion data.


string = FloatToString( INT )


Converting a string to a numeric value/variable

StringToInt$(string)

Converts a string of numeric ASCII data into an integer numeric data value.


string = String variable containing numeric ASCII data.

returns numeric data from the string in decimal form.


number = StringToInt$( string )


Converting a string into a floating point value/variable

StringToFloat$( string )

Converts a string of numeric ASCII data into a floating point variable.


string = String variable containing numeric ASCII data.

returns numeric data from the string in floating point form.


float = StringToFloat$( string )