time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (6388B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2021 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # substringAfterLast
     22 
     23 > Return the part of a string after the last occurrence of a specified substring.
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var substringAfterLast = require( '@stdlib/string/substring-after-last' );
     41 ```
     42 
     43 #### substringAfterLast( str, search\[, fromIndex] ) 
     44 
     45 Returns the part of a string after the last occurrence of a specified substring.
     46 
     47 ```javascript
     48 var str = 'beep boop';
     49 var out = substringAfterLast( str, 'b' );
     50 // returns 'oop'
     51 
     52 out = substringAfterLast( str, 'o' );
     53 // returns 'p'
     54 ```
     55 
     56 By default, the search starts at the end of the string and proceeds backwards to the beginning. To start the search at a specified index, specify an integer for the `fromIndex` argument.
     57 
     58 ```javascript
     59 var str = 'beep boop';
     60 var out = substringAfterLast( str, 'b', 3 );
     61 // returns 'eep boop'
     62 ```
     63 
     64 </section>
     65 
     66 <!-- /.usage -->
     67 
     68 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     69 
     70 <section class="notes">
     71 
     72 ## Notes
     73 
     74 -   If a substring is not present in a provided string, the function returns an empty string.
     75 -   If provided an empty substring, the function returns an empty string.
     76 
     77 </section>
     78 
     79 <!-- /.notes -->
     80 
     81 <!-- Package usage examples. -->
     82 
     83 <section class="examples">
     84 
     85 ## Examples
     86 
     87 <!-- eslint no-undef: "error" -->
     88 
     89 ```javascript
     90 var substringAfterLast = require( '@stdlib/string/substring-after-last' );
     91 
     92 var str = 'To be, or not to be, that is the question.';
     93 var out = substringAfterLast( str, ', ' );
     94 // returns 'that is the question.'
     95 
     96 out = substringAfterLast( str, 'to be' );
     97 // returns ', that is the question.'
     98 
     99 out = substringAfterLast( str, 'question.' );
    100 // returns ''
    101 
    102 out = substringAfterLast( str, 'xyz' );
    103 // returns ''
    104 
    105 out = substringAfterLast( str, '' );
    106 // returns ''
    107 ```
    108 
    109 </section>
    110 
    111 <!-- /.examples -->
    112 
    113 <!-- Section for describing a command-line interface. -->
    114 
    115 * * *
    116 
    117 <section class="cli">
    118 
    119 ## CLI
    120 
    121 <!-- CLI usage documentation. -->
    122 
    123 <section class="usage">
    124 
    125 ### Usage
    126 
    127 ```text
    128 Usage: substring-after-last [options] --search=<string> [<string>]
    129 
    130 Options:
    131 
    132   -h,    --help                Print this message.
    133   -V,    --version             Print the package version.
    134          --search string       Search string.
    135          --from-index int      Index at which to start the search.
    136          --split sep           Delimiter for stdin data. Default: '/\\r?\\n/'.
    137 ```
    138 
    139 </section>
    140 
    141 <!-- /.usage -->
    142 
    143 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    144 
    145 <section class="notes">
    146 
    147 ### Notes
    148 
    149 -   If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes.
    150 
    151     ```bash
    152     # Not escaped...
    153     $ echo -n $'foo\nbar\nbaz' | substring-after-last --search a --split /\r?\n/
    154 
    155     # Escaped...
    156     $ echo -n $'foo\nbar\nbaz' | substring-after-last --search a --split /\\r?\\n/
    157     ```
    158 
    159 -   The implementation ignores trailing delimiters.
    160 
    161 </section>
    162 
    163 <!-- /.notes -->
    164 
    165 <!-- CLI usage examples. -->
    166 
    167 <section class="examples">
    168 
    169 ### Examples
    170 
    171 ```bash
    172 $ substring-after-last abcdefg --search d
    173 efg
    174 ```
    175 
    176 To use as a [standard stream][standard-streams],
    177 
    178 ```bash
    179 $ echo -n $'bar\nbaz' | substring-after-last --search b
    180 ar
    181 az
    182 ```
    183 
    184 By default, when used as a [standard stream][standard-streams], the implementation assumes newline-delimited data. To specify an alternative delimiter, set the `split` option.
    185 
    186 ```bash
    187 $ echo -n 'bar\tbaz' | substring-after-last --search b --split '\t'
    188 ar
    189 az
    190 ```
    191 
    192 </section>
    193 
    194 <!-- /.examples -->
    195 
    196 </section>
    197 
    198 <!-- /.cli -->
    199 
    200 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    201 
    202 <section class="references">
    203 
    204 </section>
    205 
    206 <!-- /.references -->
    207 
    208 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
    209 
    210 <section class="related">
    211 
    212 * * *
    213 
    214 ## See Also
    215 
    216 -   <span class="package-name">[`@stdlib/string/substring-before`][@stdlib/string/substring-before]</span><span class="delimiter">: </span><span class="description">return the part of a string before a specified substring.</span>
    217 -   <span class="package-name">[`@stdlib/string/substring-before-last`][@stdlib/string/substring-before-last]</span><span class="delimiter">: </span><span class="description">return the part of a string before the last occurrence of a specified substring.</span>
    218 -   <span class="package-name">[`@stdlib/string/substring-after`][@stdlib/string/substring-after]</span><span class="delimiter">: </span><span class="description">return the part of a string after a specified substring.</span>
    219 
    220 </section>
    221 
    222 <!-- /.related -->
    223 
    224 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    225 
    226 <section class="links">
    227 
    228 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
    229 
    230 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    231 
    232 <!-- <related-links> -->
    233 
    234 [@stdlib/string/substring-before]: https://github.com/stdlib-js/string/tree/main/substring-before
    235 
    236 [@stdlib/string/substring-before-last]: https://github.com/stdlib-js/string/tree/main/substring-before-last
    237 
    238 [@stdlib/string/substring-after]: https://github.com/stdlib-js/string/tree/main/substring-after
    239 
    240 <!-- </related-links> -->
    241 
    242 </section>
    243 
    244 <!-- /.links -->