v1.2.0.1-beta1

Description

Extends String object.

Public Member Functions

string arg (value)
 
string format (format, args)
 
string simplified ()
 
string appendLine (String line, int maxLines, separator='\n')
 
string getLines (int maxLines, int fromLine=0, String separator='\n')
 

Static Public Member Functions

string appendLine (String text, String line, int maxLines, String separator='\n')
 
string getLines (String text, int maxLines, int fromLine=0, String separator='\n')
 

Member Function Documentation

◆ arg()

string arg (   value)

Returns a copy of this string with the lowest numbered place marker replaced by value.

Place markers begin with a % symbol followed by a number in the 1 through 99 range, i.e. %1, %2, ..., %99.

The following example prints "There are 20 items":

var message = "There are %1 items"
var count = 20
console.log(message.arg(count))
See also
String.format(), sprintf()

◆ format()

string format (   format,
  args 
)

Formats format string using the provided arguments in args, if any, using .NET-style formatting syntax.

Parameters
formatThe formatting string used to format the additional arguments.
argsZero or more arguments for the format string.

Formatting is done using format strings almost completely compatible with the String.Format method in Microsoft .NET Framework.

For example:

"Welcome back, {0}! Last seen {1:M}",
"John Doe", new Date(1985, 3, 7, 12, 33)
);
// output: "Welcome back, John Doe! Last seen April 07"
Date prototype extension methods
Extends String object.
string format(format, args)
Formats format string using the provided arguments in args, if any, using .NET-style formatting synta...

There is also a convenience global function available as an alias, named simply Format(). It works identically to String.format() but is shorter to type.

See formatting string reference at
https://learn.microsoft.com/en-us/dotnet/standard/base-types/formatting-types

This extension is originally from the String.format for JavaScript project. There are some examples and references available at that site. The original sffjs object referenced in their documentation is available in this script engine as Sffjs.

See also
Number.format(), Date.format(), and sprintf() for "printf-style" string formatting.

◆ simplified()

string simplified ( )

Returns this string with leading, trailing, and all redundant internal whitespace removed.

contents of this byte array as a Base64-encoded string. Example:

var str = " lots\t of\nwhitespace\r\n ";
str = str.simplified();
// str == "lots of whitespace";

◆ appendLine() [1/2]

string appendLine ( String  line,
int  maxLines,
  separator = '\n' 
)

Appends string line to current string, and returns a new block with up to maxLines lines.

If maxLines is zero or negative, returns the full resulting string. The newline (\n) is used as separator by default, or a custom separator string can be specified in separator argument.

◆ appendLine() [2/2]

string appendLine ( String  text,
String  line,
int  maxLines,
String  separator = '\n' 
)
static

Appends string line to text and returns a new block with up to maxLines lines.

Static version of String.prototype.appendLine(), above. Used, for example, like this: String.appendLine("Original string", "New line to append", 4)

◆ getLines() [1/2]

string getLines ( int  maxLines,
int  fromLine = 0,
String  separator = '\n' 
)

Splits string text into lines based on separator and returns maxLines of text starting at fromLine (zero-based index).

Default maxLines is 1, fromLine is zero (the start) and default separator is "\n". Specify a negative fromLine to count lines from the end instead of the beginning (so -1 returns one line from the end). The result may be the complete input if there were fewer then maxLines found in it.

◆ getLines() [2/2]

string getLines ( String  text,
int  maxLines,
int  fromLine = 0,
String  separator = '\n' 
)
static

Splits string text into lines based on separator and returns maxLines of text starting at fromLine (zero-based index).

Static version of String.prototype.getLines(), above. Used, for example, like this: String.getLines("Text\nWith some\nLines\n", 1, -1)