StringPlus: Difference between revisions

4,145 bytes added ,  21 May 2009
no edit summary
*>Monkey 05 06
No edit summary
*>Monkey 05 06
No edit summary
Line 167: Line 167:
{{textcolor|#FF0000|Example:}}
{{textcolor|#FF0000|Example:}}


   String str = "This is some text.";
   String haystack = "This is some text.";
   Display("contains %d spaces and punctuation.", str.ContainsHowManyOf(" .,;:!?"));
   Display("contains %d spaces and punctuation.", haystack.ContainsHowManyOf(" .,;:!?"));


Displays "contains '''4''' spaces and punctuation.".
Displays "contains '''4''' spaces and punctuation.".


''See Also:'' {{link||String.ContainsAllOf}}, {{link||String.ContainsNOf}}, {{link||String.ContainsOnly}}, {{link||String.ContainsNoneOf}}
''See Also:'' {{link||String.ContainsAllOf}}, {{link||String.ContainsNOf}}, {{link||String.ContainsNoneOf}}, {{link||String.ContainsOnly}}


====String.ContainsAllOf====
====String.ContainsAllOf====
Line 178: Line 178:


Returns whether the String contains all of the characters in '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
Returns whether the String contains all of the characters in '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
{{textcolor|#FF0000|Example:}}
  String haystack = "Hello, my name is Ego. What is your name?";
  bool result = haystack.ContainsAllOf(" .,;:!?");
  if (result) {
    Display("The haystack has all of the punctuation characters in it.");
  }
  else {
    Display("The haystack did not have all the punctuation characters in it.");
  }
''See Also:'' {{link||String.ContainsHowManyOf}}, {{link||String.ContainsNOf}}, {{link||String.ContainsNoneOf}}, {{link||String.ContainsOnly}}


====String.ContainsNOf====
====String.ContainsNOf====
Line 183: Line 196:


Returns whether the String contains at least N instances of characters from the '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
Returns whether the String contains at least N instances of characters from the '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
{{textcolor|#FF0000|Example:}}
  String haystack = "This is some text.";
  if (haystack.ContainsNOf(" .,;:!?", 4)) {
    Display("the haystack contains at least 4 spaces and punctuation.");
  }
  else {
    Display("the haystack only contains %d spaces and punctuation.", haystack.ContainsHowManyOf(" .,;:!?"));
  }
''See Also:'' {{link||String.ContainsHowManyOf}}, {{link||String.ContainsAllOf}}, {{link||String.ContainsNoneOf}}, {{link||String.ContainsOnly}}
====String.ContainsNoneOf====
''bool String.ContainsNoneOf(String characterSet, optional bool caseSensitive)''
Returns whether the String contains none of the characters defined in '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
{{textcolor|#FF0000|Example:}}
  String haystack = "This is some text.";
  if (haystack.ContainsNoneOf(" .,;:!?")) {
    Display("the haystack contains no spaces or punctuation.");
  }
  else {
    Display("the haystack contains %d spaces and punctuation.", haystack.ContainsHowManyOf(" .,;:!?"));
  }
''See Also:'' {{link||String.ContainsHowManyOf}}, {{link||String.ContainsAllOf}}, {{link||String.ContainsNOf}}, {{link||String.ContainsOnly}}


====String.ContainsOnly====
====String.ContainsOnly====
Line 189: Line 231:
Returns whether the String contains only the characters defined in '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
Returns whether the String contains only the characters defined in '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.


====String.ContainsNoneOf====
{{textcolor|#FF0000|Example:}}
''bool String.ContainsNoneOf(String characterSet, optional bool caseSensitive)''
 
  String haystack = "This is some text.";
  if (haystack.ContainsOnly("abcdefghijklmnopqrstuvwxyz0123456789")) {
    Display("the haystack contains only alphanumeric characters.");
  }
  else {
    Display("the haystack contains non-alphanumeric characters.");
  }
 
Displays that the haystack string is not alphanumeric. The {{link||String.IsAlphaNumeric}} function is an easier way to perform this same test.


Returns whether the String contains none of the characters defined in '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
''See Also:'' {{link||String.ContainsHowManyOf}}, {{link||String.ContainsAllOf}}, {{link||String.ContainsNOf}}, {{link||String.ContainsNoneOf}}, {{link||String.IsAlphaNumeric}}


====String.IndexOfCase====
====String.IndexOfCase====
Line 198: Line 249:


Works the same as {{link|String functions|String.IndexOf}}, but allows case sensitivity. Unlike most functions in this module, '''CASESENSITIVE''' is ''TRUE'' by default. Returns the index of '''NEEDLE''' in the String.
Works the same as {{link|String functions|String.IndexOf}}, but allows case sensitivity. Unlike most functions in this module, '''CASESENSITIVE''' is ''TRUE'' by default. Returns the index of '''NEEDLE''' in the String.
{{textcolor|#FF0000|Example:}}
  String haystack = "String haystack = "The haystack had a needle in it somewhere.";
  int noCase = haystack.IndexOf("A NEEDLE");
  int case = haystack.IndexOfCase("A NEEDLE");
  if (noCase == -1) {
    Display("The string didn't contain the needle (without case sensitivity).");
  }
  else {
    Display("a needle was found (without case sensitivity) starting at character %d in the string.", noCase);
  }
  if (case == -1) {
    Display("The string didn't contain the needle (with case sensitivity).");
  }
  else {
    Display("a needle was found (with case sensitivity) starting at character %d in the string.", noCase);
  }
Displays "a needle was found (without case sensitivity) starting at character 17 in the string." and then "The string didn't contain the needle (with case sensitivity).".
''See Also:'' {{link|String functions|String.IndexOf}}, {{link||String.IndexOfChar}}, {{link||String.IndexOfNth}}


====String.IndexOfChar====
====String.IndexOfChar====
Line 203: Line 276:


Returns the index of char '''C''' in the String. Unlike most functions in the module, '''CASESENSITIVE''' is ''TRUE'' by default.
Returns the index of char '''C''' in the String. Unlike most functions in the module, '''CASESENSITIVE''' is ''TRUE'' by default.
{{textcolor|#FF0000|Example:}}
  String haystack = "This is some text.";
  int result = haystack.IndexOfChar('x');
  if (result == -1) {
    Display("the haystack did not contain the character 'x'.");
  }
  else {
    Display("the character 'x' was found at index %d.", result);
  }
''See Also:'' {{link|String functions|String.IndexOf}}, {{link||String.IndexOfCase}}, {{link||String.IndexOfNth}}


====String.IndexOfNth====
====String.IndexOfNth====
Line 208: Line 294:


Returns the '''N'''th instance of '''NEEDLE''' in the String. '''CASESENSITIVE''' is ''FALSE'' by default. '''SEARCHDIRECTION''' is ''eForwards'' by default and allows you to search the String from either end. '''RETURNLAST''' is ''TRUE'' by default and controls whether the last instance of '''NEEDLE''' should be used in place of the '''N'''th if the String contains fewer than '''N''' instances.
Returns the '''N'''th instance of '''NEEDLE''' in the String. '''CASESENSITIVE''' is ''FALSE'' by default. '''SEARCHDIRECTION''' is ''eForwards'' by default and allows you to search the String from either end. '''RETURNLAST''' is ''TRUE'' by default and controls whether the last instance of '''NEEDLE''' should be used in place of the '''N'''th if the String contains fewer than '''N''' instances.
{{textcolor|#FF0000|Example:}}
  String haystack = "Needles? We don't need no stinkin' needles!";
  int result = haystack.IndexOfNth("needle", 2, false, eForwards, false); // let's make sure we ''really'' have 2 instances
  if (result == -1) {
    Display("There were fewer than 2 instances of needle in the haystack.");
  }
  else {
    Display("The second needle appears at index %d.", result);
  }
Displays "The second needle appears at index 35.". By passing '''FALSE''' for ''returnLast'' we can ensure that there are at least 2 instances of "needle" in the haystack string; otherwise if it contained any instances it would return the last instance.
''See Also:'' {{link|String functions|String.IndexOf}}, {{link||String.IndexOfCase}}, {{link||String.IndexOfChar}}


====String.FindNthNotOf====
====String.FindNthNotOf====
Anonymous user