Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

str index-of for strings

Returns start index of first occurrence of string in input, or -1 if no match.

Signature

> str index-of {flags} (string) ...rest

Flags

  • --grapheme-clusters, -g: count indexes using grapheme clusters (all visible chars have length 1)
  • --utf-8-bytes, -b: count indexes using UTF-8 bytes (default; non-ASCII chars have length 2+)
  • --range, -r {range}: optional start and/or end index
  • --end, -e: search from the end of the input

Parameters

  • string: The string to find in the input.
  • ...rest: For a data structure input, search strings at the given cell paths, and replace with result.

Input/output types:

inputoutput
list<string>list<int>
recordrecord
stringint
tabletable

Examples

Returns index of string in input

>  'my_library.rb' | str index-of '.rb'
10

Count length using grapheme clusters

> '🇯🇵ほげ ふが ぴよ' | str index-of --grapheme-clusters 'ふが'
4

Returns index of string in input within arhs open range

>  '.rb.rb' | str index-of '.rb' --range 1..
3

Returns index of string in input within a lhs open range

>  '123456' | str index-of '6' --range ..4
-1

Returns index of string in input within a range

>  '123456' | str index-of '3' --range 1..4
2

Returns index of string in input

>  '/this/is/some/path/file.txt' | str index-of '/' -e
18