String splitting is the process of breaking up a text string in a systematic way so that the individual parts of the text can be processed. This is typically used when coding comma-delimited spontaneous awareness data, but works with any list of items. Once the items are split into an individual variables for each item mentioned, you can use the Text Categorization tool along with a custom prompt to classify the mentions into categories.
For variables with few mentions and is easily parsed, you can use JavaScript to split up the strings (otherwise R may be a better option). This article describes how to go from a single variable where commas separate the 1st, 2nd, and 3rd mentions, and so on ...
To store each mention in a separate variable:
Requirements
- A data set loaded into Displayr that contains a text variable where multiple responses are stored in a single variable as comma-separated text values.
Method
- Hover over any variable in your Data Sources and click Plus (+) > Custom Code > JavaScript > Text. A new variable will be created in the Data Sources tree.
-
Next, copy and paste the code below into the JavaScript code
panel:
// Define the text variable to split var string = awareness // Define the delimiter var split_string = string.split(","); // Extract the first string of before the delimiter (first string field = 0, second string field = 1 etc) var result = split_string[0] // Return the result resultNote that you will need to update Line 2 of the code, replacing awareness with the Name of your text variable.
On Line 5 of the code, update the comma to the delimiter that is used in your text variable as necessary.
Variables for 2nd brand mentioned, 3rd mention, and so on, can be added by repeating the process above and modifying Line 8 of the code to refer to columns 1, 2, 3, etc. (see comment in Line 7) of the table of split elements.
- Click Calculate.
- With this new variable selected, go to Properties
, under General > General, give the variable a Label and a Name.
This code does the following things:
The split() method is used to split a string into an array of substrings, and it returns a new array.
Tip: If an empty string ("") is used as the separator, the string is split between each character.
Note: The split() method does not change the original string.
The syntax:
string.split(separator, limit)OPTIONAL: The separator specifies the character, or the regular expression, to use for splitting the string, as in the example above, ",". If omitted, the entire string will be returned (an array with only one item).
OPTIONAL: limit is an integer that specifies the number of splits, items after the split limit will not be included in the array.
Next
Finding the Best Text Analysis for your Data