| w3Utils Reference |
Reference
Methods |
|
| |
|
| Adjusts all linebreaks in
a given string so that all breaks are valid CRLF sequences. This is useful for ensuring that the text will have it's linebreaks interpreted correctly and look as it should in any environment. var correctLineBreaks = StringUtils.AdjustLineBreaks( stringWithIncorrectBreaks ); |
|
| |
|
| Converts a datastring to
a Hex sequence. Can be used for dumping memory, converting blobs into SQL usable strings.
|
|
| |
|
| Returns the content-type
given a filename Checks registry on computer for filetype information. var contType = StringUtils.ContentType( 'afile.gif' ); |
|
| |
|
Returns a number
representing the given value (dwNum) in the base supplied (bBase). In
essence converts the base of a number to a user defined base.StringUtils.ConvertBase( 4642160200, 16 ); // Returns a Hexadecimal string |
|
| |
|
| Formats a currency
variable to string using the locale of the computer. Given a currency value in the format specified in the computer control panel, Currency2String returns the value as a plain number in a string. See also the String2Currency function. var aCurrency = new String ( '1,225,125.00' ); var stringOfValue = StringUtils.Currency2String( aCurrency ); |
|
| |
|
| Cuts text from a string
to a string literal. Finds the string szFrom in the given string (szString) and cuts everything from there to szTo. var aDocument = '\<HTML\>A Document of some insignificance.\<BR\>\<\/HTML\>'; var bDocument = StringUtils.CutText( aDocument, "\<HTML\>", "\<\/HTML\>" ); // aDocument: <HTML>A Document of some insignificance.<BR></HTML> // bDocument: A Document of some insignificance.<BR> |
|
| |
|
| Mask a string and removes
all characters defined in MASK. Useful for removing unwanted characters in a code in order to extract it's value, among other things. var aCode = '123-4567-89912'; var valueOfaCode = StringUtils.DeMaskString( aCode, '-' ); // valueOfaCode now contains '123456789912' |
|
| |
|
| Unquotes a string that
have been QuotedStr:ed Basically is an undo/reversal of the StringUtils.QuotedStr method. See QuotedStr below for furter details. var aString = '\'Here is a string with simple quotes.\''; var fixedString = StringUtils.QuotedStr( aString ); var unFixedString = StringUtils.ExtractQuotedStr( fixedString, '\'' ); |
|
| |
|
| Formats a currency
according to the pattern specified. The pattern is composed according to the following: 0 Digit placeholder. If the value being formatted has a digit in the position where the '0' appears in the format string, then that digit is copied to the output string. Otherwise, a '0' is stored in that position in the output string. # Digit placeholder. If the value being formatted has a digit in the position where the '#' appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string. . Decimal point. The first '.' character in the format string determines the location of the decimal separator in the formatted value; any additional '.' characters are ignored. The actual character used as a the decimal separator in the output string is determined by the DecimalSeparator global variable. The default value of DecimalSeparator is specified in the Number Format of the International section in the Windows Control Panel. , Thousand separator. If the format string contains one or more ',' characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of ',' characters in the format string does not affect the output, except to indicate that thousand separators are wanted. The actual character used as a the thousand separator in the output is determined by the ThousandSeparator global variable. The default value of ThousandSeparator is specified in the Number Format of the International section in the Windows Control Panel. E+ Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-' E- are contained in the format string, the number is formatted using e+ scientific notation. A group of up to four '0' characters can e- immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the minimum number of digits in the exponent. The 'E+' and 'e+' formats cause a plus sign to be output for positive exponents and a minus sign to be output for negative exponents. The 'E-' and 'e-' formats output a sign character only for negative exponents. 'xx' Characters enclosed in single or double quotes are output as-is, and "xx" do not affect formatting. ; Separates sections for positive, negative, and zero numbers in the format string. The locations of the leftmost '0' before the decimal point in the format string and the rightmost '0' after the decimal point in the format string determine the range of digits that are always present in the output string. The number being formatted is always rounded to as many decimal places as there are digit placeholders ('0' or '#') to the right of the decimal point. If the format string contains no decimal point, the value being formatted is rounded to the nearest whole number. If the number being formatted has more digits to the left of the decimal separator than there are digit placeholders to the left of the '.' character in the format string, the extra digits are output before the first digit placeholder. To allow different formats for positive, negative, and zero values, the format string can contain between one and three sections separated by semicolons. One section - The format string applies to all values. Two sections - The first section applies to positive values and zeros, and the second section applies to negative values. Three sections - The first section applies to positive values, the second applies to negative values, and the third applies to zeros. If the section for negative values or the section for zero values is empty, that is if there is nothing between the semicolons that delimit the section, the section for positive values is used instead. var aNumber = new Number ( 1234569 ); var currencyOfNumber = StringUtils.FormatCurrency( aNumber, '### ### ###.##' ); // basically use # and whatever you like. // Note however how the character you use for comma is dependent on your system // settings. In this example '.' is used |
|
| |
|
Calculates a Hash value
of a stringaString = 'Test string'; var hashValue = StringUtils.HashString ( aString ); // hashValue = 66450 |
|
| |
|
| Returns the index of the
first wildcard in a string. If none is present then zero is returned. Wildcards are for example the asterisk '*'. var wildString = 'adads*dsad'; var firstWild = StringUtils.HasWildCards( wildString ); // firstWild = 6 after this |
|
| |
|
| Converts a numeric
variable to Hexadecimal. NumChars is an optional parameter specifying the length of the string returned. It fills with zeroes to the specified length. var aNumber = Number ( 770217 ); var aHexNumber = StringUtils.Hex( aNumber, 8 ); // aHexNumber = '000BC0A9' |
|
| |
|
| Produces a Hexdump of a
datastring. Output is fixed formatted using spaces and not tab-delimited. For HTML output use tags and a fixed width font. var dumpString = 'asdaasdaasdaasdaasdaasda'; var hexDump = StringUtils.HexDump( dumpString ); // produces the following: // 00000000 61 73 64 61 61 73 64 61 61 73 64 61 61 73 64 61 asdaasdaasdaasda // 00000010 61 73 64 61 61 73 64 61 asdaasda |
|
| |
|
| HTMLEncodes text. This function takes care of substituting international characters (such as 'ÅÄÖÜ') with their respective HTML codes (such as 'Å'). If the optional parameter ProcessHTTPLinks is supplied as true the method also takes any text that is a HTTP URL and puts an anchor tag with the URL as HREF value in it. var htmlText = 'Characters: åäö and a link: http://www.dimac.net'; var codeText = StringUtils.HTMLEncode ( htmlText, true ); // codeText gets the content: // 'Characters: åäö and a link: <A HREF="http://www.dimac.net">http://www.dimac.net</A>' |
|
| |
|
| Reformats a string and
inserts a before each CRLF sequence. Good for HTML use when text data is retrieved from a database and published on the web. var htmlText = 'A break: \r\n...and a continuing text.'; var codeText = StringUtils.HTMLFormatBreaks ( htmlText ); // codeText contents becomes: // A break: <BR> // ...and a continuing text. |
|
| |
|
| Indents a string. Simply puts as many spaces as the number supplied ('Columns') in front of each line. Use tags to accomplished desired result on a HTML page. var indentedText = StringUtils.Indent( unindentedText, 10 ); |
|
| |
|
| JScriptEncode encodes a
string so that it can be used within a JScript/JavaScript statement. It converts the cr, lf, tab characters to \r, \n and \t etc. var encodedText = StringUtils.JScriptEncode( aText ); |
|
| |
|
Trims all breakable
characters on the left side of a string.var unTrimmed = ' asdasd asdasd adsd'; var leftTrimmed = StringUtils.LTrim ( unTrimmed ); // leftTrimmed contains: 'asdasd asdasd adsd' |
|
| |
|
| Encodes a string in
ISO8859-1 format. Can be useful in SMTP Mail headers and so on. var encodedString = StringUtils.MakeISO8859_1( aString ); |
|
| |
|
| Masks a string to only
contain characters specified in MASK Useful to extract only essential characters from some code or other string. var unMasked = '82 13 45 - 6712 - 787'; var maskResult = StringUtils.MaskString( unMasked, '0123456789' ); // maskResult contains: '8213456712787' |
|
| |
|
Matches two strings.
Pattern can contain wildcards.var eMail = 'john.doe@domain.doe'; var isMatch = StringUtils.Match( eMail, "*@*.*" ); // isMatch will be true |
|
| |
|
Decodes a string encoded
with MimeEncode or any other base64 encoded string.var decodedText = StringUtils.MimeDecode( encodedText ); |
|
| |
|
Base64 encodes a string
of datavar encodedText = StringUtils.MimeEncode( aText ); |
|
| |
|
Decodes a
Quoted-Printable encoded string.var decodedText = StringUtils.QPDecode( encodedText ); |
|
| |
|
Applies Quoted-Printable
encoding to a stringvar encodedText = StringUtils.QPEncode( aText ); |
|
| |
|
| Creates a Quoted string
ready for use with SQL statements etc. This function does two things: Puts quotes around the string and codes any characters inside of the string correctly, such as quotes and so on. It is useful when putting data from a form into a database, for example. // retrieving userdata from a HTML form var name = StringUtils.QuotedStr( Request.Form( 'name' ).item ); var email = StringUtils.QuotedStr( Request.Form( 'email' ).item ); sql = 'SELECT ID, Address FROM users WHERE name = ' + name + ' AND email = ' + email; |
|
| |
|
| Replaces all substrings
specified with another. Searches the szString for any occurences of the SearchFor string and replaces them with the ReplaceWith string. var aLongString = 'John A Johnsson. John has been employed since 1991. John is a good guy.'; var anotherString = StringUtils.Replace( aLongString, 'John', 'Eric' ); // aLongString and anotherString contain: // John A Johnsson. John has been employed since 1991. John is a good guy. // Eric A Ericsson. Eric has been employed since 1991. Eric is a good guy. |
|
| |
|
Reverses a string.var aLongString = 'John A Johnsson. John has been employed since 1991. John is a good guy.'; var reversedString = StringUtils.ReverseString( aLongString ); // reversedString contains: // '.yug doog a si nhoJ .1991 ecnis deyolpme neeb sah nhoJ .nossnhoJ A nhoJ' |
|
| |
|
| Trims all breakable
characters to the right of a string. See also LTrim. var unTrimmed = ' asdasd asdasd adsd '; var rightTrimmed = StringUtils.RTrim ( unTrimmed ); // rightTrimmed contains: ' asdasd asdasd adsd' |
|
| |
|
Calculates the soundex
value of a stringvar aLongString = 'John A Johnsson. John has been employed since 1991. John is a good guy.'; var sValue = StringUtils.Soundex( aLongString ); // sValue contains: J525 |
|
| |
|
| Converts a Currency
string to a Currency variable. See also the Currency2String function. var aCurrency = ( '$12251.25' ); var aCurrency = StringUtils.String2Currency( aCurrencyString ); |
|
| |
|
| Trims all breakable
characters of the beginning and end of a string A combination of LTrim and RTrim. var unTrimmed = ' asdasd asdasd adsd '; var Trimmed = StringUtils.Trim ( unTrimmed ); // rightTrimmed contains: 'asdasd asdasd adsd' |
|
| |
|
| Trims quotes of a String Function addresses (")-quotes. var stringWithQuotes = '"Hello there George!"'; var stringWithout = StringUtils.TrimQuotes( stringWithQuotes ); // String values are: // "Hello there George!" // Hello there George! |
|
| |
|
| Wraps text into columns
with options to justify margins, multicolumar text etc. The text is formatted using spaces. wrappedText = StringUtils.WrapText( szMyText, 50, true, 2, " " ); |