TextProcessing

Assembly: ZennoLab.Macros
Full name: ZennoLab.Macros.TextProcessing


Helper class for text operations

Methods

Split

Method

Splits the string.

Parameters

ПараметрОписание
sourceStringThe source string.
separatorDelimiter for text in the string.
numberThe 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

ПараметрОписание
sourceStringThe source string.
separatorDelimiter 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

ПараметрОписание
sourceStringThe source string.
extendedSyntaxUse 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

ПараметрОписание
countOfCharsThe count of chars in result text.
optionsThe set of options (“d” - use digits, “c” - use big letters, “s” - use only customSymbols, “f” - first letter is large)
customSymbolsThe 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

ПараметрОписание
sourceStringThe 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

ПараметрОписание
dllNameDLL library.
textThe source text.
targetLangugeTarget language.
sourceLanguageSource language (default: auto).
proxyStrProxy URL string
additionalParametersAdditional 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

ПараметрОписание
sourceStringThe source string.
encodingNameName 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

ПараметрОписание
sourceStringThe source string.
encodingNameName 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

ПараметрОписание
sourceStringThe 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

ПараметрОписание
sourceStringSource 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

ПараметрОписание
sourceStringThe source string.
methodThe 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

ПараметрОписание
sourceStringThe source string.
methodThe 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

ПараметрОписание
sourceStringThe source string.
whereToTrimThe 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

ПараметрОписание
sourceStringThe source string.
symbolsThe specified characters for trim operation as string object.
whereToTrimThe 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

ПараметрОписание
sourceStringThe source string.
rowSplitterThe splitter of the rows in String object.
rowSplitterTypeThe split type of the rows in String object. It can have the following values: Text or Regex.
projectThe project object in which need store the data.
listThe 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

ПараметрОписание
sourceStringThe source string.
rowSplitterThe splitter of the rows in String object.
colSplitterThe splitter of the colums in String object.
projectThe project object in which need store the data.
rowSplitterTypeThe split type of the rows in String object. It can have the following values: Text or Regex.
colSplitterTypeThe split type of the colums in String object. It can have the following values: Text or Regex.
tableThe 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

ПараметрОписание
sourceStringThe source string.
findThe string to be replaced.
replaceThe string to replace occurrences of find.
searchTypeThe type of the search find. It can have the following values: Text or Regex.
takeThe type of the performance of replacing in String object. It can have the following values: All, First, Last, Number or Range.
parametersThe 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

ПараметрОписание
sourceStringThe source string.
sourceRegexThe target regex.
rangeThe range of collections for return.
excludeGroupThe 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

ПараметрОписание
strString 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- }"