Vst String

0 views
Skip to first unread message

Tiana Dubree

unread,
Aug 5, 2024, 12:34:50 AM8/5/24
to alacexin
Stringsare useful for holding data that can be represented in text form. Some of the most-used operations on strings are to check their length, to build and concatenate them using the + and += string operators, checking for the existence or location of substrings with the indexOf() method, or extracting substrings with the substring() method.

String literals can be specified using single or double quotes, which are treated identically, or using the backtick character `. This last form specifies a template literal: with this form you can interpolate expressions. For more information on the syntax of string literals, see lexical grammar.


When using bracket notation for character access, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See Object.defineProperty() for more information.)


The choice of whether to transform by toUpperCase() or toLowerCase() is mostly arbitrary, and neither one is fully robust when extending beyond the Latin alphabet. For example, the German lowercase letter and ss are both transformed to SS by toUpperCase(), while the Turkish letter ı would be falsely reported as unequal to I by toLowerCase() unless specifically using toLocaleLowerCase("tr").


String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (that is, called without using the new keyword) are primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup on the wrapper object instead.


String primitives and String objects also give different results when using eval(). Primitives passed to eval are treated as source code; String objects are treated as all other objects are, by returning the object. For example:


Many built-in operations that expect strings first coerce their arguments to strings (which is largely why String objects behave similarly to string primitives). The operation can be summarized as follows:


Strings are represented fundamentally as sequences of UTF-16 code units. In UTF-16 encoding, every code unit is exact 16 bits long. This means there are a maximum of 216, or 65536 possible characters representable as single UTF-16 code units. This character set is called the basic multilingual plane (BMP), and includes the most common characters like the Latin, Greek, Cyrillic alphabets, as well as many East Asian characters. Each code unit can be written in a string with \u followed by exactly four hex digits.


On top of Unicode characters, there are certain sequences of Unicode characters that should be treated as one visual unit, known as a grapheme cluster. The most common case is emojis: many emojis that have a range of variations are actually formed by multiple emojis, usually joined by the (U+200D) character.


You must be careful which level of characters you are iterating on. For example, split("") will split by UTF-16 code units and will separate surrogate pairs. String indexes also refer to the index of each UTF-16 code unit. On the other hand, [Symbol.iterator]() iterates by Unicode code points. Iterating through grapheme clusters will require some custom code.


They are of limited use, as they are based on a very old HTML standard and provide only a subset of the currently available HTML tags and attributes. Many of them create deprecated or non-standard markup today. In addition, they do simple string concatenation without any validation or sanitation, which makes them a potential security threat when directly inserted using innerHTML. Use DOM APIs such as document.createElement() instead.


\n Strings are useful for holding data that can be represented in text form. Some of the\n most-used operations on strings are to check their length, to build and concatenate them using the\n + and += string operators,\n checking for the existence or location of substrings with the\n indexOf() method, or extracting substrings\n with the substring() method.\n


\n String literals can be specified using single or double quotes, which are treated\n identically, or using the backtick character `. This last form specifies a template literal:\n with this form you can interpolate expressions. For more information on the syntax of string literals, see lexical grammar.\n


\n When using bracket notation for character access, attempting to delete or assign a\n value to these properties will not succeed. The properties involved are neither writable\n nor configurable. (See Object.defineProperty() for more information.)\n


The choice of whether to transform by toUpperCase() or toLowerCase() is mostly arbitrary, and neither one is fully robust when extending beyond the Latin alphabet. For example, the German lowercase letter and ss are both transformed to SS by toUpperCase(), while the Turkish letter ı would be falsely reported as unequal to I by toLowerCase() unless specifically using toLocaleLowerCase(\"tr\").


\n String literals (denoted by double or single quotes) and strings returned from\n String calls in a non-constructor context (that is, called without using\n the new keyword) are primitive strings. In contexts where a\n method is to be invoked on a primitive string or a property lookup occurs, JavaScript\n will automatically wrap the string primitive and call the method or perform the property\n lookup on the wrapper object instead.\n


\n String primitives and String objects also give different results when\n using eval(). Primitives passed to\n eval are treated as source code; String objects are treated as\n all other objects are, by returning the object. For example:\n


Strings are represented fundamentally as sequences of UTF-16 code units. In UTF-16 encoding, every code unit is exact 16 bits long. This means there are a maximum of 216, or 65536 possible characters representable as single UTF-16 code units. This character set is called the basic multilingual plane (BMP), and includes the most common characters like the Latin, Greek, Cyrillic alphabets, as well as many East Asian characters. Each code unit can be written in a string with \\u followed by exactly four hex digits.


You must be careful which level of characters you are iterating on. For example, split(\"\") will split by UTF-16 code units and will separate surrogate pairs. String indexes also refer to the index of each UTF-16 code unit. On the other hand, [Symbol.iterator]() iterates by Unicode code points. Iterating through grapheme clusters will require some custom code.


The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example: String str = "abc"; is equivalent to: char data[] = 'a', 'b', 'c'; String str = new String(data); Here are some more examples of how strings can be used: System.out.println("abc"); String cde = "cde"; System.out.println("abc" + cde); String c = "abc".substring(2,3); String d = cde.substring(1, 2); The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification. Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown. A String represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in the Character class for more information). Index values refer to char code units, so a supplementary character uses two positions in a String. The String class provides methods for dealing with Unicode code points (i.e., characters), in addition to those for dealing with Unicode code units (i.e., char values).Since: JDK1.0See Also:Object.toString(), StringBuffer, StringBuilder, Charset, Serialized FormField Summarystatic ComparatorCASE_INSENSITIVE_ORDER

A Comparator that orders String objects as by compareToIgnoreCase. Constructor SummaryString()

Initializes a newly created String object so that it represents an empty character sequence.String(byte[] bytes)

Constructs a new String by decoding the specified array of bytes using the platform's default charset.String(byte[] bytes, Charset charset)

Constructs a new String by decoding the specified array of bytes using the specified charset.String(byte[] ascii, int hibyte)

Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a Charset, charset name, or that use the platform's default charset.String(byte[] bytes, int offset, int length)

Constructs a new String by decoding the specified subarray of bytes using the platform's default charset.String(byte[] bytes, int offset, int length, Charset charset)

Constructs a new String by decoding the specified subarray of bytes using the specified charset.String(byte[] ascii, int hibyte, int offset, int count)

Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a Charset, charset name, or that use the platform's default charset.String(byte[] bytes, int offset, int length, String charsetName)

Constructs a new String by decoding the specified subarray of bytes using the specified charset.String(byte[] bytes, String charsetName)

Constructs a new String by decoding the specified array of bytes using the specified charset.String(char[] value)

Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.String(char[] value, int offset, int count)

Allocates a new String that contains characters from a subarray of the character array argument.String(int[] codePoints, int offset, int count)

Allocates a new String that contains characters from a subarray of the Unicode code point array argument.String(String original)

Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.String(StringBuffer buffer)

Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.String(StringBuilder builder)

Allocates a new string that contains the sequence of characters currently contained in the string builder argument. Method Summary charcharAt(int index)

Returns the char value at the specified index. intcodePointAt(int index)

Returns the character (Unicode code point) at the specified index. intcodePointBefore(int index)

Returns the character (Unicode code point) before the specified index. intcodePointCount(int beginIndex, int endIndex)

Returns the number of Unicode code points in the specified text range of this String. intcompareTo(String anotherString)

Compares two strings lexicographically. intcompareToIgnoreCase(String str)

Compares two strings lexicographically, ignoring case differences. Stringconcat(String str)

Concatenates the specified string to the end of this string. booleancontains(CharSequence s)

Returns true if and only if this string contains the specified sequence of char values. booleancontentEquals(CharSequence cs)

Compares this string to the specified CharSequence. booleancontentEquals(StringBuffer sb)

Compares this string to the specified StringBuffer.static StringcopyValueOf(char[] data)

Returns a String that represents the character sequence in the array specified.static StringcopyValueOf(char[] data, int offset, int count)

Returns a String that represents the character sequence in the array specified. booleanendsWith(String suffix)

Tests if this string ends with the specified suffix. booleanequals(Object anObject)

Compares this string to the specified object. booleanequalsIgnoreCase(String anotherString)

Compares this String to another String, ignoring case considerations.static Stringformat(Locale l, String format, Object... args)

Returns a formatted string using the specified locale, format string, and arguments.static Stringformat(String format, Object... args)

Returns a formatted string using the specified format string and arguments. byte[]getBytes()

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. byte[]getBytes(Charset charset)

Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array. voidgetBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)

Deprecated. This method does not properly convert characters into bytes. As of JDK 1.1, the preferred way to do this is via the getBytes() method, which uses the platform's default charset. byte[]getBytes(String charsetName)

Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array. voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)

Copies characters from this string into the destination character array. inthashCode()

Returns a hash code for this string. intindexOf(int ch)

Returns the index within this string of the first occurrence of the specified character. intindexOf(int ch, int fromIndex)

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. intindexOf(String str)

Returns the index within this string of the first occurrence of the specified substring. intindexOf(String str, int fromIndex)

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. Stringintern()

Returns a canonical representation for the string object. booleanisEmpty()

Returns true if, and only if, length() is 0. intlastIndexOf(int ch)

Returns the index within this string of the last occurrence of the specified character. intlastIndexOf(int ch, int fromIndex)

Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. intlastIndexOf(String str)

Returns the index within this string of the rightmost occurrence of the specified substring. intlastIndexOf(String str, int fromIndex)

Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index. intlength()

Returns the length of this string. booleanmatches(String regex)

Tells whether or not this string matches the given regular expression. intoffsetByCodePoints(int index, int codePointOffset)

Returns the index within this String that is offset from the given index by codePointOffset code points. booleanregionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)

Tests if two string regions are equal. booleanregionMatches(int toffset, String other, int ooffset, int len)

Tests if two string regions are equal. Stringreplace(char oldChar, char newChar)

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. Stringreplace(CharSequence target, CharSequence replacement)

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. StringreplaceAll(String regex, String replacement)

Replaces each substring of this string that matches the given regular expression with the given replacement. StringreplaceFirst(String regex, String replacement)

Replaces the first substring of this string that matches the given regular expression with the given replacement. String[]split(String regex)

Splits this string around matches of the given regular expression. String[]split(String regex, int limit)

Splits this string around matches of the given regular expression. booleanstartsWith(String prefix)

Tests if this string starts with the specified prefix. booleanstartsWith(String prefix, int toffset)

Tests if the substring of this string beginning at the specified index starts with the specified prefix. CharSequencesubSequence(int beginIndex, int endIndex)

Returns a new character sequence that is a subsequence of this sequence. Stringsubstring(int beginIndex)

Returns a new string that is a substring of this string. Stringsubstring(int beginIndex, int endIndex)

Returns a new string that is a substring of this string. char[]toCharArray()

Converts this string to a new character array. StringtoLowerCase()

Converts all of the characters in this String to lower case using the rules of the default locale. StringtoLowerCase(Locale locale)

Converts all of the characters in this String to lower case using the rules of the given Locale. StringtoString()

This object (which is already a string!) is itself returned. StringtoUpperCase()

Converts all of the characters in this String to upper case using the rules of the default locale. StringtoUpperCase(Locale locale)

Converts all of the characters in this String to upper case using the rules of the given Locale. Stringtrim()

Returns a copy of the string, with leading and trailing whitespace omitted.static StringvalueOf(boolean b)

Returns the string representation of the boolean argument.static StringvalueOf(char c)

Returns the string representation of the char argument.static StringvalueOf(char[] data)

Returns the string representation of the char array argument.static StringvalueOf(char[] data, int offset, int count)

Returns the string representation of a specific subarray of the char array argument.static StringvalueOf(double d)

Returns the string representation of the double argument.static StringvalueOf(float f)

Returns the string representation of the float argument.static StringvalueOf(int i)

Returns the string representation of the int argument.static StringvalueOf(long l)

Returns the string representation of the long argument.static StringvalueOf(Object obj)

Returns the string representation of the Object argument. Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait Field DetailCASE_INSENSITIVE_ORDERpublic static final Comparator CASE_INSENSITIVE_ORDERA Comparator that orders String objects as by compareToIgnoreCase. This comparator is serializable. Note that this Comparator does not take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides Collators to allow locale-sensitive ordering.Since: 1.2See Also:Collator.compare(String, String)Constructor DetailStringpublic String()Initializes a newly created String object so that it represents an empty character sequence. Note that use of this constructor is unnecessary since Strings are immutable.Stringpublic String(String original)Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable.Parameters:original - A StringStringpublic String(char[] value)Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the newly created string.Parameters:value - The initial value of the stringStringpublic String(char[] value, int offset, int count)Allocates a new String that contains characters from a subarray of the character array argument. The offset argument is the index of the first character of the subarray and the count argument specifies the length of the subarray. The contents of the subarray are copied; subsequent modification of the character array does not affect the newly created string.Parameters:value - Array that is the source of charactersoffset - The initial offsetcount - The lengthThrows:IndexOutOfBoundsException - If the offset and count arguments index characters outside the bounds of the value arrayStringpublic String(int[] codePoints, int offset, int count)Allocates a new String that contains characters from a subarray of the Unicode code point array argument. The offset argument is the index of the first code point of the subarray and the count argument specifies the length of the subarray. The contents of the subarray are converted to chars; subsequent modification of the int array does not affect the newly created string.Parameters:codePoints - Array that is the source of Unicode code pointsoffset - The initial offsetcount - The lengthThrows:IllegalArgumentException - If any invalid Unicode code point is found in codePointsIndexOutOfBoundsException - If the offset and count arguments index characters outside the bounds of the codePoints arraySince: 1.5String@Deprecatedpublic String(byte[] ascii, int hibyte, int offset, int count)Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a Charset, charset name, or that use the platform's default charset.Allocates a new String constructed from a subarray of an array of 8-bit integer values. The offset argument is the index of the first byte of the subarray, and the count argument specifies the length of the subarray. Each byte in the subarray is converted to a char as specified in the method above.Parameters:ascii - The bytes to be converted to charactershibyte - The top 8 bits of each 16-bit Unicode code unitoffset - The initial offsetcount - The lengthThrows:IndexOutOfBoundsException - If the offset or count argument is invalidSee Also:String(byte[], int), String(byte[], int, int, java.lang.String), String(byte[], int, int, java.nio.charset.Charset), String(byte[], int, int), String(byte[], java.lang.String), String(byte[], java.nio.charset.Charset), String(byte[])String@Deprecatedpublic String(byte[] ascii, int hibyte)Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a Charset, charset name, or that use the platform's default charset.Allocates a new String containing characters constructed from an array of 8-bit integer values. Each character cin the resulting string is constructed from the corresponding component b in the byte array such that: c == (char)(((hibyte & 0xff)

3a8082e126
Reply all
Reply to author
Forward
0 new messages