TextProcessing
Assembly: ZennoLab.Macros
Full name: ZennoLab.Macros.TextProcessing
Kind: abstract
Helper class for text operations
Methods
Split
Method
IEnumerable<string> Split(string sourceString, string separator, string number)
Splits the string.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
string | separator | Delimiter for text in the string. |
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
string RemoveDuplicates(string sourceString, string separator)
Removes duplicates.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
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
string Spintax(string sourceString, bool extendedSyntax)
Spintaxes the string.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
bool | 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
string RandomText(int countOfChars, string options, string customSymbols)
Gets the random text.
Parameters
| Type | Name | Description |
|---|---|---|
int | countOfChars | The count of chars in result text. |
string | options | The set of options (“d” - use digits, “c” - use big letters, “s” - use only customSymbols, “f” - first letter is large) |
string | 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
string Translit(string sourceString)
Converts the string to translit.
Parameters
| Type | Name | Description |
|---|---|---|
string | 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
string Translate(string dllName, string text, string targetLanguge, string sourceLanguage, string proxyStr, string additionalParameters)
Translate text through the specified DLL library.
Parameters
| Type | Name | Description |
|---|---|---|
string | dllName | DLL library. |
string | text | The source text. |
string | targetLanguge | Target language. |
string | sourceLanguage | Source language (default: auto). |
string | proxyStr | Proxy URL string |
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
string UrlEncode(string sourceString, string encodingName)
Encodes the string to UrlEncode.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
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
string UrlDecode(string sourceString, string encodingName)
Decodes the string from UrlEncode.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
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
string PrepToJavaScriptEval(string sourceString)
Performs the text preparing for JavaScript evaluation.
Parameters
| Type | Name | Description |
|---|---|---|
string | 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
string ToChar(string sourceString)
Converts the integer value in specified string to a Unicode character.
The sourceString must be a string that contains a single character.
Parameters
| Type | Name | Description |
|---|---|---|
string | 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
string ToLower(string sourceString, string method)
Returns a copy of this string converted to lowercase in specified place.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
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
string ToUpper(string sourceString, string method)
Returns a copy of this string converted to uppercase in specified place.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
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
string Trim(string sourceString, string whereToTrim)
Removes all leading and trailing, leading or trailing white-space, tabulations and end of line characters from the current String object.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
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
string Trim(string sourceString, string symbols, string whereToTrim)
Removes all leading and trailing, leading or trailing specified characters from the current String object.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
string | symbols | The specified characters for trim operation as string object. |
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 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
void ToList(string sourceString, string rowSplitter, string rowSplitterType, IZennoPosterProjectModel project, IZennoList list)
Converts all items in specified string to the list of the project model.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
string | rowSplitter | The splitter of the rows in String object. |
string | rowSplitterType | The split type of the rows in String object. It can have the following values: Text or Regex. |
IZennoPosterProjectModel | project | The project object in which need store the data. |
IZennoList | 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
void ToTable(string sourceString, string rowSplitter, string rowSplitterType, string colSplitter, string colSplitterType, IZennoPosterProjectModel project, IZennoTable table)
Converts all items in specified string to the table of the project model.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
string | rowSplitter | The splitter of the rows in String object. |
string | rowSplitterType | The split type of the rows in String object. It can have the following values: Text or Regex. |
string | colSplitter | The splitter of the colums in String object. |
string | colSplitterType | The split type of the colums in String object. It can have the following values: Text or Regex. |
IZennoPosterProjectModel | project | The project object in which need store the data. |
IZennoTable | 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
string Replace(string sourceString, string find, string replace, string searchType, string take, string parameters)
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
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
string | find | The string to be replaced. |
string | replace | The string to replace occurrences of find. |
string | searchType | The type of the search find. It can have the following values: Text or Regex. |
string | take | The type of the performance of replacing in String object. It can have the following values: All, First, Last, Number or Range. |
string | 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
List<List<string>> Regex(string sourceString, string sourceRegex, string range, string excludeGroup)
Returns groups collection of matches for target regex.
Parameters
| Type | Name | Description |
|---|---|---|
string | sourceString | The source string. |
string | sourceRegex | The target regex. |
string | range | The range of collections for return. |
string | 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
string StringMacrosScreening(string str)
Escapes macros.
Parameters
| Type | Name | Description |
|---|---|---|
string | 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- }"