One 、js String example 1

 <script type="text/javascript">
var strobject = new String('123abc123abc');
// Traverses each character in the output string
for (var i = 0; i < strobject.length; i++) {
document.write(strobject[i] + "<br>");
} // Output the character at the specified position
for (var i = 0; i < strobject.length; i++) {
document.write(strobject.charAt(i) + "<br>");
} // Outputs the Unicode code
for (var i = 0; i < strobject.length; i++) {
document.write(strobject.charCodeAt(i) + "<br>");
} // String search
document.write(strobject.indexOf("1" + "<br>"));
document.write(strobject.lastIndexOf("1"));
</script>

Two 、js String example 2

<script type="text/javascript">
var str1 = new String("123");
var str2 = new String("abc123a");
// String merge
var str3 = str1.concat(str2);
document.write(str3);
document.write(str1.indexOf("a")+"<br>");
// String substitution --- Put the first one in the string oldStr Replace with newStr
document.write(str2.replace("a", "A"));
var strLong = new String("123a456a789");
// String slice --- Specify the starting position , Or specify the end position
document.write(strLong.slice(0, 1) + "<br>");
document.write(strLong.slice(3)+"<br>");
document.write(strLong.slice(1, 2) + "<br>");
// String interception ----- Specify the start position and intercept length
document.write(strLong.substr(1, 2) + "<br>");
document.write(strLong.substr(1, strLong.length - 1)+"<br>");
document.write(strLong.substr(2,strLong.length));
// String interception ----- Specify the start and end positions ( Does not include end position )
document.write(strLong.substring(0, 1) + "<br>");
document.write(strLong.substring(1,strLong.length)+"<br>");
// String segmentation --- Specify the separator and the number of splits , Returns the split string array
var str4 = "-www-baido-com";
document.write(str4.split("-")+"<br>");
document.write(str4.split("-", 2) + "<br>");
// toggle case
document.write(str4.toUpperCase() + "<br>");
document.write("ABCd".toLowerCase());
</script>

more :

JavaScript Array ( 3、 ... and ) Array objects use collation

JavaScript Array ( Two ) example

Javascript Array ( One ) Sort

Javascript character string ( One ) More articles about the use of common functions

  1. Javascript character string ( Two ) Common operation arrangement

    One .js Get the number of bytes in the string This works well --- function getBytesLength(str) { // stay GBK In the code , except ASCII character , Everything else is two characters wide return str.repla ...

  2. JavaScript Summary of string practical operation

    JavaScript Strings are used to store and process text . So I'm writing JS She's always with me when I code , When you process user input data , In reading or setting DOM Object's properties , In operation Cookie when , In the transformation of all kinds of different Da ...

  3. JavaScript String manipulation

    JavaScript Strings are used to store and process text . So I'm writing JS She's always with me when I code , When you process user input data , In reading or setting DOM Object's properties , In operation Cookie when , In the transformation of all kinds of different Da ...

  4. JavaScript String common operations

    JavaScript Strings are used to store and process text . So I'm writing JS She's always with me when I code , When you process user input data , In reading or setting DOM Object's properties , In operation Cookie when , In the transformation of all kinds of different Da ...

  5. JavaScript character string (String) object

    JavaScript  character string (String)  object String Object is used to process existing character blocks . JavaScript character string A string is used to store a series of characters, like "John Doe". ...

  6. IE JavaScript The string is converted to Date Later NaN error

    Reference blog post :http://blog.csdn.net/zhu7478848/article/details/53388582 stay IE browsers , JavaScript The string is converted to Date And then there will be NaN wrong ...

  7. JavaScript Summary of common string operations

    JavaScript Strings are used to store and process text . So I'm writing JS She's always with me when I code , When you process user input data , In reading or setting DOM Object's properties , In operation Cookie when , In the transformation of all kinds of different Da ...

  8. JavaScript String insertion 、 Delete 、 Substitution function

    JavaScript String insertion . Delete . Substitution function explain : The first two of the following functions take out the first and second parts of the lookup string , For other functions . Be careful , Call once replaceString(mainStr,search ...

  9. javascript String method

    javascript String methods pass parameters because of nested single quotation marks , Too many double quotes . Is a little confusing .. The correct way is as follows : '   <td align="left"><input type= ...

Random recommendation

  1. HTML5_06 Drag and drop API、Worker Threads 、Storage Storage

    1. Drag and drop API Data transfer between source object and target object events in : ① Create global variables -- The global object of pollution :  var Global variables =null;  src.ondragstart=function(){    Global variables = Data values ;  ...

  2. arm Embedded cross compiler tool chain

    1.arm-linux-gcc Common parameters :-o[ Make the output file name ] -c[ Until compilation stops , Not connected ] -g[ Type debug information ] -xO[ Optimization level ] -w/W( Warning level ) arm-linux-gcc -o de ...

  3. java The conversion between binary and stream in

    It's binary public static byte[] toByteArray(InputStream in) throws IOException { ByteArrayOutputStream ou ...

  4. Android Get mobile phone manufacturers , System version, etc

    In development Sometimes we need to get the system version of the current mobile phone to judge , Or you need to get some hardware information of the current mobile phone . android.os.Build Class . Including some information like this . We can call You don't need to add any permissions and ...

  5. GridView in DataKeyNames Application summary of

    One . GridView Of DataKeyNames Property set to "ID,Name" GridView1.DataKeyNames = new string[]{ "ID" ...

  6. css The implementation skills of the reveal button

    <html> <title>css</title> <style> button{ padding: .3em .8em; border: 1px so ...

  7. --@ui-router——$state Details of the original service

    $state service in module ui.router.state Description $state service is responsible for representing ...

  8. AOP Face to face programming in Android The use of

    GitHub Address ( Welcome to download the complete Demo) https://github.com/ganchuanpu/AOPDemo Project requirements description I think it's like this personal centric interface , No one is strange to you . Those places with arrows ...

  9. MySQL Use in sql Statement to get the table structure

    Recent research PHP, Then it has to be about mysql. One of the functions is to automatically generate pages from table data , Then we found that the data could not be read in an empty table ( Because they just built it , It's empty. There's no data ) The extension is to directly look up the table structure to get the field name , I'll go on ...

  10. Mybatis Business ( One ) How to manage affairs

    Mybatis There are two ways to manage affairs : (1) Use JDBC Transaction management mechanism of , Is the use java.sql.Connection Object to commit the transaction (2) Use MANAGED Transaction management mechanism of , Such mechanism mybat ...