Difference between revisions of "Programmer Guide/Command Reference/STRCHR"

From STX Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
  <var>var</var> := STRCHR [ /Reverse ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [[XXX|/-]] <var>needle</var> <var>haystackstring</var>
+
  <var>var</var> := STRCHR [ /Reverse ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>needle</var> <var>haystackstring</var>
  <var>var</var> := STRCHR [ /Reverse ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]]] /Variable [[XXX|/-]] <var>needle</var> <var>haystackvariable</var>
+
  <var>var</var> := STRCHR [ /Reverse ] [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]]] /Variable [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>needle</var> <var>haystackvariable</var>
  
 
Locates the first occurrence of the character <var>character</var>, or one of the characters in <var>characters</var> in the string <var>haystackstring</var> or, if <code>/Variable</code> is supplied, in the variable <var>haystackvariable</var>. and returns the index of the first occurrence, or -1, if no occurrence is found.
 
Locates the first occurrence of the character <var>character</var>, or one of the characters in <var>characters</var> in the string <var>haystackstring</var> or, if <code>/Variable</code> is supplied, in the variable <var>haystackvariable</var>. and returns the index of the first occurrence, or -1, if no occurrence is found.
Line 11: Line 11:
 
;<code>/Variable</code>
 
;<code>/Variable</code>
 
:This option tells {{STX}} that the haystack argument is the name of a variable whose contents are to be searched. When omitting <code>/Variable</code>, the haystack argument will be considered a string literal to search.
 
:This option tells {{STX}} that the haystack argument is the name of a variable whose contents are to be searched. When omitting <code>/Variable</code>, the haystack argument will be considered a string literal to search.
;<code>[[XXX|/-]]</code>
+
;<code>[[Programmer_Guide/Command_Reference_Options/-|/-]]</code>
:The "end of options" option tells {{STx}} that any further arguments are plain arguments, even should they start with a slash. You should always use this option in order to prevent - unless, of course, if you can be entirely sure that none of your arguments will start with a slash.
+
:The [[Programmer_Guide/Command_Reference_Options/-|"end of options" option]] tells {{STx}} that any further arguments are plain arguments, even should they start with a slash. You should always use this option in order to prevent - unless, of course, if you can be entirely sure that none of your arguments will start with a slash.
 
;<var>needle</var>
 
;<var>needle</var>
 
:A string of characters, or a single character, to search for.
 
:A string of characters, or a single character, to search for.
Line 19: Line 19:
  
 
  #v := set 'You must be joking ;-)'
 
  #v := set 'You must be joking ;-)'
  #i := strchr /Variable [[XXX|/-]] ';' '#v'
+
  #i := strchr /Variable [[Programmer_Guide/Command_Reference_Options/-|/-]] ';' '#v'
 
  // #i == 19
 
  // #i == 19

Revision as of 18:57, 29 April 2014

var := STRCHR [ /Reverse ] [ /Silent ] /- needle haystackstring
var := STRCHR [ /Reverse ] [ /Silent] /Variable /- needle haystackvariable

Locates the first occurrence of the character character, or one of the characters in characters in the string haystackstring or, if /Variable is supplied, in the variable haystackvariable. and returns the index of the first occurrence, or -1, if no occurrence is found.

/Reverse
If option /Reverse is supplied, the haystack will be searched from right to left; otherwise, it will be searched from left to right.
/Silent
If option /Silent is set, warnings instead of errors will be generated on failure
/Variable
This option tells STx that the haystack argument is the name of a variable whose contents are to be searched. When omitting /Variable, the haystack argument will be considered a string literal to search.
/-
The "end of options" option tells STx that any further arguments are plain arguments, even should they start with a slash. You should always use this option in order to prevent - unless, of course, if you can be entirely sure that none of your arguments will start with a slash.
needle
A string of characters, or a single character, to search for.
haystackvariable
Find the first semi-colon in the string stored in the variable haystackvariable.
#v := set 'You must be joking ;-)'
#i := strchr /Variable /- ';' '#v'
// #i == 19