How-tos: Strings

Specifying a directory in the "Calculate a Value" field

Using Multiple Hotkeys

Description

There are scenarios where we want to read files from a path such as \\tsclient\Z\Foreign workers\Contracts. However, for most programming languages — including JavaScript —, a single backslash is used to denote an escape character, such as \n, \t, \f, etc.

In this article, we show you how to specify paths such as \\tsclient\Z\Foreign workers\Contracts in the "Calculate a value" parameter of an activity.

Instructions

Using double backslashes

To specify a backslash () in the "Calculate a value" parameter, we need to prefix it with another backslash. So, the result is \.

If you need to specify two backslashes as in the path \\tsclient then you need to prefix each backslash in the path with a backslash as \\\\tsclient.

Here is an example. Let's say that we need to fill the "Calculate a value" parameter with the path

\\tsclient\Z\Foreign workers\Contracts

Considering the instructions above, the resulting value must be:

\\\\tsclient\\Z\\Foreign workers\\Contracts.

🚧

Note

It is crucial that we handle escape sequences correctly. Otherwise, the following exception message may appear at the bottom of the "Calculate a value" field of the activity.

Using normal slashes
As an alternative, we can also use a normal slash (/).

For example:

"C:\\Exch\\" + expDate + ".csv"

"C:/Exch/" + expDate + ".csv"

⬅️

Back to the table


Inserting Line Breaks

Description

Sometimes we want to insert line breaks while entering a value in an application such as Notepad, Wordpad, WhatsApp, etc.

Here is an example:

In this article, you will learn how to insert a line break using the Input to desktop app activity. For further details, you can check the video at the end of the content.

Instructions

To insert a link break, follow these steps:

  1. Enable the "Use additional syntax for sending keys" parameter in the Input to desktop app activity

  2. If you want to enter the value Hello How are you? one after another, for example, you can use the following syntax:

Hello{ENTER}How are you?

Notice that some applications have a specific scenario: if you hit "Enter", the value is actually submitted instead of inserting a line break. In cases such as this, you can click on the "Input from the keyboard" option and press the key combination that inserts a line break in that application.

For example, if you hit "Enter" in WhatsApp, the value is actually submitted. So, if you want a line break instead, you need to press "Ctrl + Enter" in WhatsApp — and the syntax code that emulates "Ctrl + Enter" in Studio Pro is ^{ENTER}.

Summing up: if you want to enter a line break in the WhatsApp application, you can do so as follows:

Hello^{ENTER}How are you?
As you can see, it is a simple process.

⬅️

Back to the table


Adding Punctuation to Numbers

Description

By default, commas are not included in numbers while working in Studio Pro. Hence, there are scenarios when we need to add commas to numbers in a document.

In this article, you will learn how to do this using the JS function toLocaleString().

Instructions

Here’s how to do it in a few steps:

  1. Add a variable to a workflow. In the example below, the variable "num" contains the value "123456789"

  2. To add commas to this number, use the syntax num.toLocaleString()

  1. To display the comma punctuation in numbers as it is done in the American system, you need to enter this syntax in the value field num.toLocaleString("en-US"), as you can see below

⬅️

Back to the table


Using special characters in texts

Description

There are scenarios when you want to insert line breaks while entering a value in an application such as Notepad, Wordpad, WhatsApp, etc.

Example:

In this article, let us see how we can insert line breaks using the ‘Input to desktop app’ activity.

Instructions

  1. Enable the parameter ‘Use additional syntax for sending keys’ in the ‘Input to desktop app’ activity
  2. If you want to enter the value “Hello How are you?” one after another using the ‘Input to desktop app’ activity, you can do so as follows:
    Hello{ENTER}How are you?
  3. There are applications when you hit ‘Enter’, the value is actually submitted instead of inserting a line break. In cases such as this, you can click on the ‘INPUT FROM THE KEYBOARD’ option, press the key combination that inserts a line break in that application
  • For example: In Whatsapp, if you hit ‘Enter’ the value is actually submitted. If you want a line break then you need to press ‘Ctrl + Enter' and the syntax that emulates ‘Ctrl + Enter’ is ^{ENTER}
  1. If you want to enter the value “Hello How are you?” one after another in the WhatsApp application using the ‘Input to desktop app’ activity, you can do so as follows:
    Hello^{ENTER}How are you?

⬅️

Back to the table


Using Regex in Strings

Description

In this article, you will learn how to use regular expressions or regex to replace a particular word in a string or remove certain characters/digits from a string.

Instructions

Here are two examples of how to do that.

A) Replacing a word in a string

For this example, imagine you want to replace the term "blue" with "red" in the following sentence:

  1. Select the "Calculate a value" option and type str.replace(/blue/g, "red").
  1. As a result, the new string must look like this:

B) Removing digits or characters from a string

Have a look at the following example and imagine you want to delete the digits from the string. Follow the steps below:

  1. Select the "Calculate a value" option and type str.replace(/[0-9]/g, '')
  1. As a result, the new string must look like this:

⬅️

Back to the table


How to add line breaks to a text file

In this article, we will learn how to split lines in a text file. The example file we'll use can be downloaded from this link.

Instructions

  1. Add the "Read text file" activity to your workflow.
  1. Specify the path to the downloaded text file.
  1. Add the "Assign value to variable" activity.
  1. Add the syntax file_content.split("\n") within the "Calculate a value" field.
  1. See the result:

⬅️

Back to the table