TextProcessing
Assembly: ZennoLab.Macros
Full name: ZennoLab.Macros.TextProcessing
Helper class for text operations
Methods
Split
Method
Splits the string.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
separator | Delimiter for text in the string. |
number | The number of string after splitting. |
Returns: A new string after splitting.
Example
var result = Macros.TextProcessing.Split("first;second;third;fourth;fifth", ";", "2").First();
return result;
// result = "second"Example2
$result = Macros::TextProcessing::Split("first;second;third;fourth;fifth", ";", "2")->First();
return $result;
// result = "second"RemoveDuplicates
Method
Removes duplicates.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
separator | Delimiter for text in the string. |
Returns: A new string without duplicates.
Example
var result = Macros.TextProcessing.RemoveDuplicates("first;first;second", ";");
return result;
// result = "first;second"Example2
$result = Macros::TextProcessing::RemoveDuplicates("first;first;second", ";");
return $result;
// result = "first;second"Spintax
Method
Spintaxes the string.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
extendedSyntax | Use extended spintax sintax. |
Returns: A spintaxed string.
Example
var result = Macros.TextProcessing.Spintax("I'm the {first|second|third|fourth|fifth} in line.");
return result;
// result = "I'm the first in line." or "I'm the second in line.", etc.Example2
$result = Macros::TextProcessing::Spintax("I'm the {first|second|third|fourth|fifth} in line.");
return $result;
// result = "I'm the first in line." or "I'm the second in line.", etc.RandomText
Method
Gets the random text.
Parameters
| Параметр | Описание |
|---|---|
countOfChars | The count of chars in result text. |
options | The set of options (“d” - use digits, “c” - use big letters, “s” - use only customSymbols, “f” - first letter is large) |
customSymbols | The custom set of letters to use with option “s”. |
Returns: The random text.
Example
var result = Macros.TextProcessing.RandomText(20, "dcf", "");Example2
$result = Macros::TextProcessing::RandomText(20, "dcf", "");Translit
Method
Converts the string to translit.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
Returns: A translit string.
Example
var result = Macros.TextProcessing.Translit("Переводим в транслит.");
return result;
// result = "Perevodim v translit."Example2
$result = Macros::TextProcessing::Translit("Переводим в транслит.");
return $result;
// result = "Perevodim v translit."Translate
Method
Translate text through the specified DLL library.
Parameters
| Параметр | Описание |
|---|---|
dllName | DLL library. |
text | The source text. |
targetLanguge | Target language. |
sourceLanguage | Source language (default: auto). |
proxyStr | Proxy URL string |
additionalParameters | Additional parameters string |
Returns: Result text.
Example
string res = Macros.TextProcessing.TextTranslate("BaiduTranslate.dll", "Hello!", "Chinese");Example2
$res = Macros::TextProcessing::TextTranslate("BaiduTranslate.dll", "Hello!", "Chinese");UrlEncode
Method
Encodes the string to UrlEncode.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
encodingName | Name of encoding, UTF-8 by default. |
Returns: A encoded string.
Example
var result = Macros.TextProcessing.UrlEncode("<");
return result;
// result = "%3C"Example2
$result = Macros::TextProcessing::UrlEncode("<");
return $result;
// result = "%3C"UrlDecode
Method
Decodes the string from UrlEncode.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
encodingName | Name of encoding. UTF-8 by default. |
Returns: A decoded string.
Example
var result = Macros.TextProcessing.UrlDecode("%3C");
return result;
// result = "<"Example2
$result = Macros::TextProcessing::UrlDecode("%3C");
return $result;
// result = "<"PrepToJavaScriptEval
Method
Performs the text preparing for JavaScript evaluation.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
Returns: The text after preparing for JavaScript evaluation.
Example
// perform the text preparing for JavaScript evaluation.
string preparedText = Macros.TextProcessing.PrepToJavaScriptEval("text for JavaScript");Example2
// perform the text preparing for JavaScript evaluation.
$preparedText = Macros::TextProcessing::PrepToJavaScriptEval("text for JavaScript");ToChar
Method
Converts the integer value in specified string to a Unicode character.
The sourceString must be a string that contains a single character.
Parameters
| Параметр | Описание |
|---|---|
sourceString | Source string. |
Returns: A Unicode character that is equivalent to the integer value in sourceString.
Example
// convert to char
string c = Macros.TextProcessing.ToChar("45");Example2
// convert to char
$c = Macros::TextProcessing::ToChar("45");ToLower
Method
Returns a copy of this string converted to lowercase in specified place.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
method | The place where need performs the operation to uppercase. It can have the following values: All, FirstLetters and FirstLetter. |
Returns: The lowercase in specified place equivalent of the current string.
Example
// performs to lower operation for all string
string allToLower = Macros.TextProcessing.ToUpper("STRING TO LOWER", "All");
// performs to lower operation for first letters
string firstLettersToLower = Macros.TextProcessing.ToUpper("STRING TO LOWER", "FirstLetters");
// performs to lower operation for first letter
string firstLetterToLower = Macros.TextProcessing.ToUpper("STRING TO LOWER", "FirstLetter");Example2
// performs to lower operation for all string
$allToLower = Macros::TextProcessing::ToUpper("STRING TO LOWER", "All");
// performs to lower operation for first letters
$firstLettersToLower = Macros::TextProcessing::ToUpper("STRING TO LOWER", "FirstLetters");
// performs to lower operation for first letter
$firstLetterToLower = Macros::TextProcessing::ToUpper("STRING TO LOWER", "FirstLetter");ToUpper
Method
Returns a copy of this string converted to uppercase in specified place.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
method | The place where need performs the operation to uppercase. It can have the following values: All, FirstLetters and FirstLetter. |
Returns: The uppercase in specified place equivalent of the current string.
Example
// performs to upper operation for all string
string allToUpper = Macros.TextProcessing.ToUpper("string to upper", "All");
// performs to upper operation for first letters
string firstLettersToUpper = Macros.TextProcessing.ToUpper("string to upper", "FirstLetters");
// performs to upper operation for first letter
string firstLetterToUpper = Macros.TextProcessing.ToUpper("string to upper", "FirstLetter");Example2
// performs to upper operation for all string
$allToUpper = Macros::TextProcessing::ToUpper("string to upper", "All");
// performs to upper operation for first letters
$firstLettersToUpper = Macros::TextProcessing::ToUpper("string to upper", "FirstLetters");
// performs to upper operation for first letter
$firstLetterToUpper = Macros::TextProcessing::ToUpper("string to upper", "FirstLetter");Trim
Method
Removes all leading and trailing, leading or trailing white-space, tabulations and end of line characters from the current String object.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
whereToTrim | The place where need performs the trim operation. It can have the following values: Begin, End or Full. |
Returns: The string that remains after all specified characters are removed from the start or end of the current string.
Example
// trim white-space and end line characters from start and end of string
string fullTrim = Macros.TextProcessing.Trim(" string for trim operation\r\n ", "Full");
// trim white-space from start of string
string beginTrim = Macros.TextProcessing.Trim(" string for trim operation\r\n ", "Begin");
// trim end line characters from end of string
string endTrim = Macros.TextProcessing.Trim(" string for trim operation\r\n ", "End");Example2
// trim white-space and end line characters from start and end of string
$fullTrim = Macros::TextProcessing::Trim(" string for trim operation\r\n ", "Full");
// trim white-space from start of string
$beginTrim = Macros::TextProcessing::Trim(" string for trim operation\r\n ", "Begin");
// trim end line characters from end of string
$endTrim = Macros::TextProcessing::Trim(" string for trim operation\r\n ", "End");Trim
Method
Removes all leading and trailing, leading or trailing specified characters from the current String object.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
symbols | The specified characters for trim operation as string object. |
whereToTrim | The place where need performs the trim operation. It can have the following values: Begin, End or Full. |
Returns: The string that remains after all specified characters are removed from the start or end of the current string.
Example
// trim specified characters from start and end of string
string fullTrim = Macros.TextProcessing.Trim("!string for trim operation?", "!?", "Full");
// trim specified characters from start of string
string beginTrim = Macros.TextProcessing.Trim("!string for trim operation?", "!?", "Begin");
// trim specified characters from end of string
string endTrim = Macros.TextProcessing.Trim("!string for trim operation?", "!?", "End");Example2
// trim specified characters from start and end of string
$fullTrim = Macros::TextProcessing::Trim("!string for trim operation?", "!?", "Full");
// trim specified characters from start of string
$beginTrim = Macros::TextProcessing::Trim("!string for trim operation?", "!?", "Begin");
// trim specified characters from end of string
$endTrim = Macros::TextProcessing::Trim("!string for trim operation?", "!?", "End");ToList
Method
Converts all items in specified string to the list of the project model.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
rowSplitter | The splitter of the rows in String object. |
rowSplitterType | The split type of the rows in String object. It can have the following values: Text or Regex. |
project | The project object in which need store the data. |
list | The list object in which need store the data. |
Example
// performs convert string data to list data by specific row splitter
Macros.TextProcessing.ToList("1 2 3 4 5 6 7 8 9 10", " ", "Text", project, project.Lists["List1"]);Example2
// performs convert string data to list data by specific row splitter
Macros::TextProcessing::ToList("1 2 3 4 5 6 7 8 9 10", " ", "Text", $project, $project->Lists->get_Item("List1"));ToTable
Method
Converts all items in specified string to the table of the project model.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
rowSplitter | The splitter of the rows in String object. |
colSplitter | The splitter of the colums in String object. |
project | The project object in which need store the data. |
rowSplitterType | The split type of the rows in String object. It can have the following values: Text or Regex. |
colSplitterType | The split type of the colums in String object. It can have the following values: Text or Regex. |
table | The table object in which need store the data. |
Example
// performs convert string data to table data by specific row and column splitters
Macros.TextProcessing.ToTable("1 2 3\r\n4 5 6\r\n7 8 9", "\r\n", "Text", " ", "Text", project, project.Tables["Table1"]);Example2
// performs convert string data to table data by specific row and column splitters
Macros::TextProcessing::ToTable("1 2 3\r\n4 5 6\r\n7 8 9", "\r\n", "Text", " ", "Text", $project, $project->Tables->get_Item("Table1"));Replace
Method
Returns a new string in which occurrences of a specified string in the current instance are replaced with another specified string.
If replace is null, all occurrences of find are removed.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
find | The string to be replaced. |
replace | The string to replace occurrences of find. |
searchType | The type of the search find. It can have the following values: Text or Regex. |
take | The type of the performance of replacing in String object. It can have the following values: All, First, Last, Number or Range. |
parameters | The additional parameter for search. This parameter applies only for Number and Range values of take. Default value is empty string. In Number case it must be number of the occurrence in string value, in Range case it must be the range of the occurrences. |
Returns: A string that is equivalent to the current string except that instances of find are replaced with replace.
Example
// replace "this" in string to "new value"
string newString = Macros.TextProcessing.Replace("replace this to new value", "this", "new value", "Text", "First");Example2
// replace "this" in string to "new value"
$newString = Macros::TextProcessing::Replace("replace this to new value", "this", "new value", "Text", "First");Regex
Method
Returns groups collection of matches for target regex.
Parameters
| Параметр | Описание |
|---|---|
sourceString | The source string. |
sourceRegex | The target regex. |
range | The range of collections for return. |
excludeGroup | The group numbers for exclude in result. |
Returns: A collection of matches
Example
// get even matches without group number 0
var matches = Macros.TextProcessing.Regex("Some string 42", @"(.+)\ (.+)", "even", "0");Example2
// get even matches without group number 0
$matches = Macros::TextProcessing::Regex("Some string 42", @"(.+)\ (.+)", "even", "0");StringMacrosScreening
Method
Escapes macros.
Parameters
| Параметр | Описание |
|---|---|
str | String to process |
Returns: A new string with escaped macros
Example
var result = Macros.TextProcessing.StringMacrosScreening("{-Variable.var1-}");
return result;
// result = "{ -Variable.var1- }"Example2
$result = Macros::TextProcessing::StringMacrosScreening("{-Variable.var1-}");
return $result;
// result = "{ -Variable.var1- }"