The Parameters
The index of the first character to include in the returned substring. indexEnd OptionalThe index of the first character to exclude from the returned substring. Return valueA new string containing the specified part of the given string. Description
Any argument value that is less than Any argument value that is
ExamplesUsing substring() The following example uses
Using substring() with length property The following example uses the
The difference between substring() and substr() There are subtle differences between the
Furthermore,
Differences between substring() and slice() The The
If either or both of the arguments are negative or
See the Replacing a substring within a string The following example replaces a substring within a string. It will replace both individual characters and substrings. The function call at the end of the example changes the string
Note that this can result in an infinite loop if A better method for replacing strings is as follows:
The code above serves as an example for substring operations. If you need to replace substrings, most of the time you will want to use
Specifications
Browser compatibilityBCD tables only load in the browser See alsoHow do I extract a single character from a string?Using String.. Get the string and the index.. Create an empty char array of size 1.. Copy the element at specific index from String into the char[] using String. getChars() method.. Get the specific character at the index 0 of the character array.. Return the specific character.. Which method is used to extract a character from string?You can extract a substring from a string using the slice() method. You pass it: the index at which to start extracting.
Which method is used to extract a single character at an index?charAt() method is used to extract a single character at an index.
How do I extract a single character from a string in C #?It basically means plucking out a certain amount of characters from an array or a string.. scanf(“%c”,&str[i]); – Using a loop.. scanf(“%s”,str); – Using %s format specifier.. gets(str); – Gets gives us an extra ability to use space in an character string/array.. |