<< Click to Display Table of Contents >> Perform string operations |
This section provide examples on how to perform the most frequently used string operations:
•Convert letters in capital letters
•Create a sub-string of a text
•Calculate the length of the string
An automated process may need to assign a value to an attribute that contains a concatenation result of two or more strings.
Suppose the first Task of the Purchase Request Process (Create Purchase Request), references three attributes (First Name, Last Name and Full Name). The Full Name attribute will be read-only, and will contain the result of concatenating the First Name and Last Name of Purchase Requester.
1.In the fourth step of the Bizagi Process Wizard, select Activity Actions.
Click the Task where this action will be performed, and create an Expression.
2. Type the Name, Display Name and Description of the expression.
3. In the Expressions Editor, add the variables FirstString and SecondString that are to be used in the expression as indicated below.
4. Create an expression to concatenate First Name and Last Name, and assign the result to the FullName variable.
The concatenation is easily done by using the addition (+) operator as shown in the image below.
//Assign attributes to variables
FirstString=<PurchaseRequest.Requester.FirstName>;
SecondString=<PurchaseRequest.Requester.LastName>;
//Assign concatenated text to the target attribute
<PurchaseRequest.Requester.FullName>=FirstString+" "+ SecondString;
Click OK.
Once the expression is associated with the process, the user can test the functionality. In the images below, the three Attributes are displayed before, and after the expression is executed. Once the expression performs the concatenation, it can be evidenced in the Full Name control.
Convert letters to Capital letters
For this example, you have to perform the same steps explained for the Concatenation example, in order to create and associate the expression with the Purchase Request process. However, in this example, the next modifications need to be performed in the expression:
1. Create the following variables for your expression.
2. Apply the .ToUpper method to the concatenated string, and assign the result to the target attribute.
//Assign attributes values to variables
FirstString=<PurchaseRequest.Requester.FirstName>;
SecondString=<PurchaseRequest.Requester.LastName>;
//Build concatenated text for the target attribute
ConcatenatedString=FirstString+" "+ SecondString;
//Convert to Capital letters
UpperString=ConcatenatedString.ToUpper();
//Assign concatenated text to the target attribute
<PurchaseRequest.Requester.FullName>=UpperString;
Once this is done, the next step is to test the changes to the expression in the Work Portal. In this example, this is done in the first activity of the Purchase Request process. The result is shown in the images below:
Note the expression is associated with an On Save event. Once you click Save in the corresponding Task, the expression will execute, and the Full Name field will be valued with the concatenation result of the First Name and Last Name, presented in capital letters.
The Substring function allows you to obtain a subset of the symbols in a string, where the order of the elements is preserved.
Suppose we wish to obtain the initials of the Requester. For this example, you have to perform the same steps explained for the Concatenate Strings example, in order to create and associate the expression with the Purchase Request process. However, in this example, the next modifications need to be performed in the expression:
1. Create the following variables:
2. Include the Substring sentence into the expression.
The Substring method has the following syntax:
String.Substring(position of initial character, number of characters);
Substring returns the specified number of characters given the position of the initial character. For instance, if you apply a substring to the text "Bizagi" with parameters 2,2 (String.Substring(2, 2)) you will obtain "za".
The next image shows the expression to obtain the initials of the Purchase Requester.
//Assign attribute values to variables
FirstString=<PurchaseRequest.Requester.FirstName>;
SecondString=<PurchaseRequest.Requester.LastName>;
//Build concatenated text calling the Substring method
Initials=FirstString.Substring(0,1)+" "+ SecondString.Substring(0,1);
//Assign concatenated result to the target attribute
<PurchaseRequest.Requester.FullName>=Initials;
Once this is done, the next step is to test the changes to the expression in the Work Portal. In this example, this is done in the first activity of the Purchase Request process. The result is shown in the images below:
The expression is associated with an Event On Save. Once the user presses the Save button, the expression will be executed. The Full Name field will be updated with the initials of the First Name and the Last Name.
Calculate the length of the string
Suppose we wish to validate that the concatenated string we obtained in the previous example of this section has, as maximum, 10 characters. If the concatenated string has more than 10 characters a substring must be applied to resize it to the required length.
To obtain the length of a string we use the .length method which returns an integer value:
String.length;
For our example it will be used to establish the condition of the validation as follows.
//Assign attribute values to variables
FirstString=<PurchaseRequest.Requester.FirstName>;
SecondString=<PurchaseRequest.Requester.LastName>;
//Build concatenated text
ConcatenatedString=FirstString+" "+ SecondString;
if (ConcatenatedString.length<10)
{
//Assign concatenated text to the target attribute
<PurchaseRequest.Requester.FullName>=ConcatenatedString;
} else
{
//Apply substring
ConcatenatedString=ConcatenatedString.Substring(0,10);
<PurchaseRequest.Requester.FullName>=ConcatenatedString;
}
Once this is done, the next step is to test the changes to the expression in the Work Portal. In this example, this is done in the first activity of the Purchase Request process. Insert a First Name and Last Name with a total number of characters greater than 10. The result is a truncated full name with only 10 characters (including the space between First and Last name), as shown in the images below:
Suppose that in a Loan Request process the passport number of customers is stored in an Integer type attribute. This number is used as parameter in a web service to consult credit blacklists, however the exposed services receives a string type parameter so a type conversion is needed from integer to string.
To convert the passport number into a string we use the .toString method:
Number.toString;
//Obtain the number to be converted
var PassportNum= <CreditRequest.Customer.PassportNumber>;
//Convert to string and assign
<CreditRequest.Customer.StrPassportNumber> = PassportNum.toString();
Suppose that in a Loan Request process the passport number of customers is stored as a string type attribute. This number is used as parameter in a web service to consult credit blacklists, however the exposed services receives an integer type parameter so a type conversion is needed from string to integer.
To convert the passport number into a integer we use the CHelper.ToInt(sText) method:
//Obtain the string to be converted
var PassportNum= <CreditRequest.Customer.PassportNumber>;
//Convert to number and assign
<CreditRequest.Customer.NumPassportNumber> = CHelper.ToInt(PassportNum);
Bizagi is built based on the Microsoft framework .Net. Therefore, SOME of the methods available from this framework can be used in Bizagi. For string operations you can use any of the following methods in your expressions:
•Clone
•Compare
•CompareOrdinal
•CompareTo
•Concat
•Contains
•Copy
•CopyTo
•Create
•EndsWith
•EnumerateRunes
•Equals
•Format
•GetEnumerator
•GetHashCode
•GetPinnableReference
•GetTypeCode
•IndexOf
•IndexOfAny
•Insert
•Intern
•IsInterned
•IsNormalized
•IsNullOrEmpty
•IsNullorWhiteSpac
•Join
•LastIndexOf
•LastIndexOfAny
•Normalize
•PadLeft
•PadRight
•Remove
•Replace
•Split
•StartsWith
•Substring
•ToCharArray
•ToLower
•ToLowerInvariant
•ToString
•ToUpper
•ToUpperInvariant
•Trim
•TrimEnd
•TrimStart
All of these methods must be used using the following syntax:
string.method
For example:
//String variable
var PassportNum= <CreditRequest.Customer.PassportNumber>;
//Method
var PassportLowerCase= PassportNum.ToLower();
All methods are case sensitive. Be Aware of upper and lower case letters in each method's name. |
For further information about these methods refer to the Microsoft .NET documentation (version 5.0):
https://docs.microsoft.com/en-us/dotnet/api/system.string?view=net-5.0#methods
Last Updated 1/6/2022 4:18:37 PM