-
-
Notifications
You must be signed in to change notification settings - Fork 23
String
These helpers provide some ability to do string manipulation.
- String.Append / String.Concat
- String.Base64Decode
- String.Base64Encode
- String.Camelcase
- String.Capitalize
- String.Contains
- String.Ellipsis
- String.IsString
- String.Join
- String.Lowercase
-
String.Occurrences
TODO - String.PascalCase
-
String.PadLeft
TODO -
String.PadRight
TODO - String.Prepend
- String.Remove
- String.Repeat
- String.Replace
- String.Reverse
- String.Split
- String.StartsWith
- String.Titlecase
- String.Trim
- String.TrimLeft
- String.TrimRight
- String.Truncate
-
String.TruncateWords
TODO - String.Uppercase
- String.Format
| Summary | Append one string to another |
| Returns | Appened string |
| Remarks | |
| Parameters | |
| str | Base string |
| suffix | String to append |
Context
{
"a": "Lorem ipsum dolor sit amet",
"b": ", consectetur adipiscing elit. Vivamus lacinia urna lectus."
}Usage
<strong>result:</strong>
{{StringAppend a b}}
{{StringAppend a " or something"}}
{{StringAppend "something or" " another"}}Returns
<strong>result:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus.
Lorem ipsum dolor sit amet or something
something or another| Summary | Base64 decode string |
| Returns | Decoded string |
| Remarks | |
| Parameters | |
| str | Base64 encoded string to decode |
Context
{
"value": "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gVml2YW11cyBsYWNpbmlhIHVybmEgbGVjdHVzLg=="
}Usage
<strong>result:</strong>
{{String.Base64Decode value}}
{{String.Base64Decode "c29tZXRoaW5nIHdpY2tlZCB0aGlzIHdheSBjb21lcw=="}}Returns
<strong>result:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus.
something wicked this way comes| Summary | Base64 encode string |
| Returns | Base64 encoded string |
| Remarks | |
| Parameters | |
| str | String to Baes64 encode |
Context
{
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus."
}Usage
<strong>result:</strong>
{{String.Base64Encode value}}
{{String.Base64Encode "something wicked this way comes"}}Returns
<strong>result:</strong>
TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gVml2YW11cyBsYWNpbmlhIHVybmEgbGVjdHVzLg==
c29tZXRoaW5nIHdpY2tlZCB0aGlzIHdheSBjb21lcw==| Summary | Truncate a long string and append a ellipsis(...) |
| Returns | Truncated string |
| Remarks | |
| Parameters | |
| str | String to truncate |
| limit | Max number of characters in final string(excluding ellipsis) |
Context
{
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus."
}Usage
<strong>result:</strong>
{{StringEllipsis value 10}}
{{StringEllipsis "something" 5}}Returns
<strong>result:</strong>
Lorem ipsu...
somet...| Summary | Join multiple strings together separated by the specified separator |
| Returns | Joined string |
| Remarks | Can be passed either an array of strings or a set of strings as arguments |
| Parameters | |
| strArray | strings to join |
| separator | Separator to used to delimit strings, default is an empty string |
Context
{
"stringArray": [
"Lorem",
"ipsum",
"dolor",
"sit",
"amet"
]
}Usage
<strong>result:</strong>
{{StringJoin stringArray " "}}
{{StringJoin stringArray}}
{{StringJoin "Lorem" "ipsum" "dolor" "sit" "amet" " "}}
{{StringJoin "Lorem" "ipsum" "dolor" "sit" "amet" ""}}
{{StringJoin "Lorem" "ipsum" "dolor" "sit" "amet"}}Returns
<strong>result:</strong>
Lorem ipsum dolor sit amet
Loremipsumdolorsitamet
Lorem ipsum dolor sit amet
Loremipsumdolorsitamet
LoremametipsumametdolorametsitNOTE: The last call in the examples, if you pass in multiple strings instead of a string array, and there are more than two strings passed in, it treats the final string as the separator/delimiator. This means that if you tried
{{StringJoin "Lorem" "ipsum" "dolor" "sit" "amet"}}and wanted to get backLoremipsumdolorsitamet, then you would actually need to add one more string to your list; ex:{{StringJoin "Lorem" "ipsum" "dolor" "sit" "amet" ""}}
| Summary | Convert string to lowercase |
| Returns | Lowercase string |
| Remarks | |
| Parameters | |
| str | input |
Context
{
"value": "Some String WITH lots of UPPERCASE letters."
}Usage
<strong>result:</strong>
{{StringLowercase value}}
{{StringLowercase "SOMETHING"}}Returns
<strong>result:</strong>
some string with lots of uppercase letters.
something| Summary | Count number of times a substring appears in base string |
| Returns | Number of times string occurred |
| Remarks | |
| Parameters | |
| str | Base string |
| substring | String to match |
| ignoreCase | Whether or not to ignore case, defaults to false |
Context
{
"value": "Some string with multiple SubStrings.",
"match": "string",
"ignoreCase": true
}Usage
<strong>result:</strong>
{{StringOccurrences value match}}
{{StringOccurrences value match ignoreCase}}
{{StringOccurrences value "string"}}
{{StringOccurrences value "string" true}}
{{StringOccurrences "something somewhere" "some"}}Returns
<strong>result:</strong>
1
2
1
2
2| Summary | Pad left input string with the padding character for a specified total length. |
| Returns | Left padded string |
| Remarks | |
| Parameters | |
| str | Base string |
| totalWidth | The number of characters in the resulting string |
| paddingChar | Padding character (not more than 1) |
Context
{
"value": "pad-me"
}Usage
<strong>result:</strong>
1. {{StringPadLeft value 10 "0"}}
2. {{StringPadLeft value "10" "0"}}
3. {{StringPadLeft "custom-string" 15 "0"}}
4. {{StringPadLeft value 15 "more-than-1-chars"}}
5. {{StringPadLeft "custom-string" 15 "more-than-1-chars"}}Returns
<strong>result:</strong>
1. 0000pad-me
2. 0000pad-me
3. 000custom-string
4. pad-me
5. custom-string| Summary | Pad right input string with the padding character for a specified total length. |
| Returns | Right padded string |
| Remarks | |
| Parameters | |
| str | Base string |
| totalWidth | The number of characters in the resulting string |
| paddingChar | Padding character (not more than 1) |
Context
{
"value": "pad-me"
}Usage
<strong>result:</strong>
1. {{StringPadRight value 10 "0"}}
2. {{StringPadRight value "10" "0"}}
3. {{StringPadRight "custom-string" 15 "0"}}
4. {{StringPadRight value 15 "more-than-1-chars"}}
5. {{StringPadRight "custom-string" 15 "more-than-1-chars"}}Returns
<strong>result:</strong>
1. pad-me0000
2. pad-me0000
3. custom-string000
4. pad-me
5. custom-string| Summary | Prepend one string to another |
| Returns | Prepend string |
| Remarks | |
| Parameters | |
| str | Base string |
| prefix | String to prepend |
Context
{
"a": "Lorem ipsum dolor sit amet",
"b": ", consectetur adipiscing elit. Vivamus lacinia urna lectus."
}Usage
<strong>result:</strong>
{{StringPrepend b a}}
{{StringPrepend a "something or "}}
{{StringPrepend "another" "something or "}}Returns
<strong>result:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus.
something or Lorem ipsum dolor sit amet
something or another| Summary | Replace matching substrings within a string with something else. |
| Returns | Replaced string |
| Remarks | Not case-insensitive |
| Parameters | |
| str | Base string |
| a | String to match |
| b | Replacement |
Context
{
"value": "Some string with multiple Substrings.",
"match": "string",
"replacement": "value"
}Usage
<strong>result:</strong>
{{StringReplace value match replacement}}
{{StringReplace value match "test"}}
{{StringReplace value "string" "test"}}
{{StringReplace value "string" replacement}}
{{StringReplace "something somewhere" "some" "test"}}Returns
<strong>result:</strong>
Some value with multiple Subvalues.
Some test with multiple Subtests.
Some test with multiple Subtests.
Some value with multiple Subvalues.
testthing testwhere| Summary | Reverse a string |
| Returns | Reversed string |
| Remarks | |
| Parameters | |
| str | Input |
Context
{
"value": "Some String WITH lots of UPPERCASE letters."
}Usage
<strong>result:</strong>
{{StringReverse value}}
{{StringReverse "SOMETHING"}}Returns
<strong>result:</strong>
.srettel ESACREPPU fo stol HTIW gnirtS emoS
GNIHTEMOS| Summary | Convert string to titlecase |
| Returns | Titlecase string |
| Remarks | |
| Parameters | |
| str | input |
Context
{
"value": "Some String WITH lots of UPPERCASE letters."
}Usage
<strong>result:</strong>
{{StringTitlecase value}}
{{StringTitlecase "SOMETHING"}}Returns
<strong>result:</strong>
Some String With Lots Of Uppercase Letters.
Something| Summary | Trim whitespace from left and right side of string |
| Returns | Trimmed string |
| Remarks | |
| Parameters | |
| str | Base string |
Context
{
"value": " Some String WITH lots of UPPERCASE letters. "
}Usage
<strong>result:</strong>
{{StringTrim value}}
{{StringTrim " SOMETHING "}}Returns
<strong>result:</strong>
Some String WITH lots of UPPERCASE letters.
SOMETHING| Summary | Trim whitespace from left side of string |
| Returns | Trimmed string |
| Remarks | |
| Parameters | |
| str | Base string |
Context
{
"value": " Some String WITH lots of UPPERCASE letters. "
}Usage
<strong>result:</strong>
{{StringTrimLeft value}}
{{StringTrimLeft " SOMETHING "}}Returns
<strong>result:</strong>
Some String WITH lots of UPPERCASE letters.
SOMETHING | Summary | Trim whitespace from right side of string |
| Returns | Trimmed string |
| Remarks | |
| Parameters | |
| str | Base string |
Context
{
"value": " Some String WITH lots of UPPERCASE letters. "
}Usage
<strong>result:</strong>
{{StringTrimRight value}}
{{StringTrimRight " SOMETHING "}}Returns
<strong>result:</strong>
Some String WITH lots of UPPERCASE letters.
SOMETHING| Summary | Truncate a long string |
| Returns | Truncated string |
| Remarks | |
| Parameters | |
| str | String to truncate |
| limit | Max number of characters in final string |
Context
{
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus."
}Usage
<strong>result:</strong>
{{StringTruncate value 10}}
{{StringTruncate "something" 5}}Returns
<strong>result:</strong>
Lorem ipsu
somet| Summary | Truncate a long string and base truncation on the number of words instead of characters and append a suffix(if set) |
| Returns | Truncated string |
| Remarks | |
| Parameters | |
| str | String to trucate |
| limit | Number of words in final string(excluding suffix) |
| suffix | Suffix to append if string gets trucated |
Context
{
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia urna lectus."
}Usage
<strong>result:</strong>
{{StringTruncateWords value 10}}
{{StringTruncateWords value 10 "..."}}
{{StringTruncateWords "something wicked this way comes" 2}}
{{StringTruncateWords "something wicked this way comes" 2 "test"}}Returns
<strong>result:</strong>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia...
something wicked
something wickedtest| Summary | Convert string to uppercase |
| Returns | Uppercase string |
| Remarks | |
| Parameters | |
| str | input |
Context
{
"value": "Some String WITH lots of lowercase letters."
}Usage
<strong>result:</strong>
{{String.Uppercase value}}
{{String.Uppercase "something"}}Returns
<strong>result:</strong>
SOME STRING WITH LOTS OF LOWERCASE LETTERS.
SOMETHING| Summary | Format a DateTime as a string |
| Returns | string |
| Remarks | |
| Parameters | |
| format | The DateTime format to use |
Context
var model = new
{
x = DateTime.Now
};Usage
<strong>result:</strong>
{{Format x \"yyyy-MMM-dd\"}}
{{Format (Now) \"yyyy-MMM-dd\"}}Returns
<strong>result:</strong>
2020-Jan-27
2020-Jan-27