StringPlus: Difference between revisions

3,122 bytes added ,  18 May 2009
no edit summary
*>Monkey 05 06
mNo edit summary
*>Monkey 05 06
No edit summary
Line 22: Line 22:


Returns a specially formatted String containing the char '''C'''. '''PADTO''' allows you to pad the String to a specific length. '''ZEROPAD''' controls whether the padding is filled with zeroes (otherwise it is filled with whitespace).
Returns a specially formatted String containing the char '''C'''. '''PADTO''' allows you to pad the String to a specific length. '''ZEROPAD''' controls whether the padding is filled with zeroes (otherwise it is filled with whitespace).
{{textcolor|FF0000|Example:}}
  String cstr = StringFromChar('A');
''cstr'' now holds the text "A".
  cstr = StringFromChar('A', 5);
''cstr'' now holds the text "     A".
  cstr = StringFromChar('A', 5, true);
''cstr'' now holds the text "0000A".
''See Also:'' {{link||StringFromFloat}}, {{link||StringFromInt}}


====StringFromFloat====
====StringFromFloat====
Line 27: Line 43:


Returns a String formatted from float '''F'''. '''PRECISION''' sets the number of digits after the decimal. '''PADTO''' allows you to pad the String to a specific length. '''ZEROPAD''' controls whether the padding is zero-filled, otherwise it is space-filled.
Returns a String formatted from float '''F'''. '''PRECISION''' sets the number of digits after the decimal. '''PADTO''' allows you to pad the String to a specific length. '''ZEROPAD''' controls whether the padding is zero-filled, otherwise it is space-filled.
{{textcolor|FF0000|Example:}}
  String fstr = StringFromFloat(3.14);
''fstr'' now holds the text "3.14".
  fstr = StringFromFloat(3.14, 3);
''fstr'' now holds the text "3.140".
  fstr = StringFromFloat(3.14, 3, 6);
''fstr'' now holds the text " 3.140". '''NOTE:''' The decimal point ''is'' included in calculating the length for padding.
  fst = StringFromFloat(3.14, 3, 6, true);
''fstr'' now holds the text "03.140".
''See Also:'' {{link||StringFromChar}}, {{link||StringFromInt}}


====StringFromInt====
====StringFromInt====
Line 32: Line 68:


Returns a String formatted from int '''I'''. '''PADTO''' allows you to pad the String to a specific length. '''ZEROPAD''' controls whether the padding is zero-filled, otherwise it is space-filled.
Returns a String formatted from int '''I'''. '''PADTO''' allows you to pad the String to a specific length. '''ZEROPAD''' controls whether the padding is zero-filled, otherwise it is space-filled.
{{textcolor|FF0000|Example:}}
  String istr = StringFromInt(27);
''istr'' now holds the text "27".
  istr = StringFromInt(27, 5);
''istr'' now holds the text "   27".
  istr = StringFromInt(27, 5, true);
''istr'' now holds the text "00027".
''See Also:'' {{link||StringFromChar}}, {{link||StringFromFloat}}


====StringMergeArray====
====StringMergeArray====
Line 37: Line 89:


Returns a String filled with each item from '''ARRAY''' in order. '''GLUE''' is inserted between each item to make it stick together of course!
Returns a String filled with each item from '''ARRAY''' in order. '''GLUE''' is inserted between each item to make it stick together of course!
{{textcolor|FF0000|Example:}}
  String sarr[] = new String[4];
  sarr[0] = "This";
  sarr[1] = "is";
  sarr[2] = "some";
  sarr[3] = "text.";
  String str = StringMergeArray(sarr, " ");
''str'' now holds the text "This is some text.".
''See Also:'' {{link||String.SplitByWidth}}, {{link||String.SplitByString}}, {{link||String.SplitByCharacterSet}}


====String.SplitByWidth====
====String.SplitByWidth====
Line 42: Line 107:


Returns a String-array containing elements of the String which when displayed in '''FONT''' are no more than '''WIDTH''' pixels wide. '''DELIMITERS''' allows you to specify a set of characters that each segment should end with. '''CASESENSITIVE''' defaults to ''FALSE''. The returned array has the first element formatted to contain the size of the rest of the array. For an array containing 5 elements, the first index (''array[0]'') would contain the text "5". This means that valid indices for the array are from ''0'' to (''array[0].AsInt + 1'').
Returns a String-array containing elements of the String which when displayed in '''FONT''' are no more than '''WIDTH''' pixels wide. '''DELIMITERS''' allows you to specify a set of characters that each segment should end with. '''CASESENSITIVE''' defaults to ''FALSE''. The returned array has the first element formatted to contain the size of the rest of the array. For an array containing 5 elements, the first index (''array[0]'') would contain the text "5". This means that valid indices for the array are from ''0'' to (''array[0].AsInt + 1'').
{{textcolor|FF0000|Example:}}
  String str = "This is a long string we're going to split into other segments.";
  String sarr[] = str.SplitByWidth(150, Game.NormalFont);
  int i = 1;
  while (i <= sarr[0].AsInt) {
    Display(sarr[i]);
    i++;
  }
Displays "This is a long string we're", " going to split into other ", and then "segments." using the default built-in fonts.
''See Also:'' {{link||StringMergeArray}}, {{link||String.SplitByString}}, {{link||String.SplitByCharacterSet}}


====String.SplitByString====
====String.SplitByString====
Line 47: Line 126:


Returns a String-array containing elements of the String. The String will be divided by instances of '''OTHERSTRING'''. The '''OTHERSTRING''' will not be included in any of the array elements. '''CASESENSITIVE''' is ''FALSE'' by default. For the formatting and size of the array, see {{link||String.SplitByWidth}}.
Returns a String-array containing elements of the String. The String will be divided by instances of '''OTHERSTRING'''. The '''OTHERSTRING''' will not be included in any of the array elements. '''CASESENSITIVE''' is ''FALSE'' by default. For the formatting and size of the array, see {{link||String.SplitByWidth}}.
{{textcolor|FF0000|Example:}}
  String str = "This is some text.";
  String sarr[] = str.SplitByString(" ");
  int i = 1;
  while (i <= sarr[0].AsInt) {
    Display(sarr[i]);
    i++;
  }
Displays the following, "This", "is", "some", and then "text.".
''See Also:'' {{link||StringMergeArray}}, {{link||String.SplitByWidth}}, {{link||String.SplitByCharacterSet}}


====String.SplitByCharacterSet====
====String.SplitByCharacterSet====
Line 52: Line 145:


Returns a String-array containing elements of the String. The String will be divided by any instance of the characters in '''CHARACTERSET''', which will not be included in the array elements. '''CASESENSITIVE''' is ''FALSE'' by default. For the formatting and size of the array, see {{link||String.SplitByWidth}}.
Returns a String-array containing elements of the String. The String will be divided by any instance of the characters in '''CHARACTERSET''', which will not be included in the array elements. '''CASESENSITIVE''' is ''FALSE'' by default. For the formatting and size of the array, see {{link||String.SplitByWidth}}.
{{textcolor|FF0000|Example:}}
  String str = "Hello, my name is Ego. What is your name?";
  String sarr[] = str.SplitByCharacterSet(".,;:!?");
  int i = 1;
  while (i <= sarr[0].AsInt) {
    Display(sarr[i]);
    i++;
  }
Displays "Hello", " my name is Ego", and then " What is your name".
''See Also:'' {{link||StringMergeArray}}, {{link||String.SplitByWidth}}, {{link||String.SplitByString}}


====String.ContainsHowManyOf====
====String.ContainsHowManyOf====
Line 57: Line 164:


Returns how many characters in the String are within the '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
Returns how many characters in the String are within the '''CHARACTERSET'''. '''CASESENSITIVE''' is ''FALSE'' by default.
{{textcolor|FF0000|Example:}}
  String str = "This is some text.";
  Display("contains %d spaces and punctuation.", str.ContainsHowManyOf(" .,;:!?"));
Displays "contains '''4''' spaces and punctuation.".
''See Also:'' {{link||String.ContainsAllOf}}, {{link||String.ContainsNOf}}, {{link||String.ContainsOnly}}, {{link||String.ContainsNoneOf}}


====String.ContainsAllOf====
====String.ContainsAllOf====
Anonymous user