Search

Dark theme | Light theme
Showing posts with label NushellNiceties:Strings. Show all posts
Showing posts with label NushellNiceties:Strings. Show all posts

September 12, 2026

Nushell Niceties: Write XML With Comments

You can learn about writing XML with Nushell n a previous blogpost. To add a XML comment you can use a record with the key tag and string value !. The content key should be a string value that is the actual comment. The result after you use the to xml is a XML text that has the format of a XML comment: <!-- content -->.

Nushell Niceties: Writing XML

In Nushell almost everything is a data structure. This mind set is also applied to XML structures in Nushell. A XML tag can be described as a record with the attributes tag, attributes and content. The tag attribute has a string value that is the tag name. Attributes are defined with a record structure. The key is the attribute name and the value is the attribute value. Finally the content attribute is a list containing a string value for text content or new record structures for nested XML tags. With this basic record structure you can describe XML content. To actually transform it to a XML string value you can use the command to xml. This command will use the data in the record structure and will output XML.

September 2, 2026

Nushell Niceties: Split String By Words

To split a string value by the words in the string you can use the command split words. The result is a list where each element is a word from the original string. You can use the option --min-word-length (or the short option -l) to specify a minimal length of the words that should be split on. When a word length is less than the given option value it will not be in the resulting list.

July 28, 2026

Nushell Niceties: Splitting String Values Into A Table

You can use the split column command to split a string value or a list of string values into a table. You need to specify a delimiter to split the value on. In the resulting table the elements are stored in columns. By default the columns have the name column<index> where index is the number of the column starting with 0. It is possible to define your own column names by specifying their names as parameters for the split column command. This way the resulting table will have more meaningful names.

April 2, 2026

Nushell Niceties: Check If Semantic Version Is A Match

In a previous blogpost you can learn about the semver command in Nushell to transform a string value into a semver type. The command has a subcommand match-req. You can use this command to check if a version matches part of the semantic version parts. The result is a boolean value. The version to compare with doesn’t have to defined fully, but could exist of only the major, minor or patch parts. The value you pass can also be used to check if a version is greater or smaller than a given version. A range with a lower and upper version to match on can be defined as well. The boundary values are separated by a comma.

December 10, 2025

Nushell Niceties: Checking String Starts Or Ends With Given String

To check if a string value starts or ends with a given string you can use the str starts-with and str ends-with commands. The command returns a boolean value: true if the string starts or ends with the given string and false otherwise. The commands are case sensitive by default. You can use the --ignore-case (or the shorthand -i) to ignore casing while checking if a the string starts or ends with a given string.
To input can be a string value and then that string value is checked. If the input is an array of string values, then each element is checked. It is also possible to check values in a record or table. You need to pass the names of the field(s) or column(s) that you want to check the string values of.

October 25, 2025

Nushell Niceties: Joining Values Into String

The string module contains a lot of useful commands to work with strings. If you want to join several values from a list into a single string you can use the str join command. The command accepts as argument the character(s) to use for joining the values. If you don't specify the character(s) as argument the default value '' (empty string) is used.

March 11, 2025

Nushell Niceties: Trimming Strings

Nushell has some powerful commands to work with strings. The str trim command can be used to trim whitespace from a string. By default whitespace from the beginning and end of a string is removed. To only remove whitespace from the beginning of the string you can use the --left argument (or the shorter option -l). For removing whitespace from the end of the string you can use the option --right or the shorter option -r. To trim a string based on another character you can use the option --char or the shorter option -c followed by the character to trim.

February 27, 2025

Nushell Niceties: Converting Strings To Kebab Case

Nushell has a lot of commands to work with strings. The str kebab-case command can be used to convert a string to kebab case. Kebab-case is a string that contains only lowercase letters and words are separated by hyphens.