String Functions

Top Previous Topic Next Topic  Print this topic

String Functions perform basic operations on strings obtained from various data sources. The supported string functions are listed below:

 

1. Concatenate - concatenates two or more input values into a resulting string.

The following example returns the concatenated values for FIRST_NAME and LAST_NAME, with a comma between them.

Concatenate

 

Note:

To add more input values, right click on the function and select Add Parameter.

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root xmlns:ns="http://www.tempuri.org/XML">

               <ns:emp first-name="John" last-name="Brown" full-name="John,Brown"/>

               <ns:emp first-name="Mary" last-name="Jane" full-name="Mary,Jane"/>

               <ns:emp first-name="Arthur" last-name="Clark" full-name="Arthur,Clark"/>

       </ns:root>

 

 

 

2. Substring - returns a substring from an input value. This function has three parameters, named string, pos and size.

string - the input string, which will be used by the function to return the substring;
pos - the position of the character that will start the substring;
size - the substring's size.

 

The following sample returns the initials of each employee's first and last name.

 

Substring

 

 

Note:

The above example is part of the Substring.dax document, located in the Samples/Job Samples folder.

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root xmlns:ns="http://www.tempuri.org/XML">

               <ns:emp first-name="John" last-name="Brown" initials="JB"/>

               <ns:emp first-name="Mary" last-name="Jane" initials="MJ"/>

               <ns:emp first-name="Arthur" last-name="Clark" initials="AC"/>

       </ns:root>

 

 

 

3. Contains - returns "true" if a string obtained from an input value contains another string. This function has two parameters: content and substring.

The following sample returns "true" if the department name contains "Develop".

Contains

 

Note:

The above example is part of the Contains.dax document, located in the Samples/Job Samples folder.

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root xmlns:ns="http://www.tempuri.org/XML">

               <ns:hist department="Accounting" contains-Develop="false"/>

               <ns:hist department="Sales" contains-Develop="false"/>

               <ns:hist department="Development" contains-Develop="true"/>

       </ns:root>

 

 

 

4. Starts-With and Ends-With functions return "true" if a string obtained from an input value starts-with (or ends-with) another string. This function must have two parameters: string and substring.

The following sample returns "true" if each DATE_MODIFIED field starts with a "7" (for July).

Starts-With

 

Note:

The above example is part of the StartsWith.dax document, located in the Samples/Job Samples folder.

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root xmlns:ns="http://www.tempuri.org/XML">

               <ns:hist date-modified="2009-07-01T00:00:00Z" modified_in_July="true"/>

               <ns:hist date-modified="2009-07-22T00:00:00Z" modified_in_July="true"/>

               <ns:hist date-modified="2009-07-16T00:00:00Z" modified_in_July="true"/>

               <ns:hist date-modified="2009-07-22T00:00:00Z" modified_in_July="true"/>

               <ns:hist date-modified="2009-07-16T00:00:00Z" modified_in_July="true"/>

               <ns:hist date-modified="2009-07-17T00:00:00Z" modified_in_July="true"/>

               <ns:hist date-modified="2009-08-27T00:00:00Z" modified_in_July="false"/>

       </ns:root>

 

 

5. Substring-after - returns a string located after an user defined set of characters to be found.

The function has two input parameters: string (the input string, which will be used by the function to return the substring) and toFind (the set of characters to be found in the input string).

 

In the example below, a string constant has been set as input ("The quick brown fox jumps over the lazy dog.") and the string to be found is "fox". The function will return " jumps over the lazy dog.

substring-after

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root After=" jumps over the lazy dog." xmlns:ns="http://www.tempuri.org/XML"/>

 

 

 

6. Substring-before - returns a string located before an user defined set of characters to be found.

The function has two input parameters: string (the input string, which will be used by the function to return the substring) and toFind (the set of characters to be found in the input string).

 

In the example below, a string constant has been set as input ("The quick brown fox jumps over the lazy dog.") and the string to be found is "fox". The function will return "The quick brown ".

substring-before

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root Before="The quick brown " xmlns:ns="http://www.tempuri.org/XML"/>

 

 

 

7. Replace - replaces a set of characters from a string with an user defined structure.

It has three input parameters: inputString (the input string), tofindString (the string to be found in the input string) and replaceString (the string that will replace the string to be found in the input string).

 

In the example below, the input string is "The quick brown fox jumps over the lazy dog.", the string to find is "brown fox" and the replace string is "turtle". The function will return: "The turtle jumps over the lazy dog."

replace_example

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root attribute-name="The quick turtle jumps over the lazy dog." xmlns:ns="http://www.tempuri.org/XML"/>

 

 

 

8. Length - returns the number of characters present in a string.

It has one input parameter, that is, the string which's length will be return.

 

In the example below, the input string is "The quick brown fox jumps over the lazy dog." and the function will return: "44".

length-string-example

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root attribute-name="44" xmlns:ns="http://www.tempuri.org/XML"/>

 

 

 

9. IsEmpty - returns a Boolean value ("true" if the string is empty, otherwise "false").

It has one input parameter, that is, the input string.

 

In the example below, the input string is "The quick brown fox jumps over the lazy dog." and the function will return: "false".

is-empty-string-example

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root attribute-name="false" xmlns:ns="http://www.tempuri.org/XML"/>