当前位置:网站首页>JS string built-in function
JS string built-in function
2022-07-16 06:05:00 【M78_ Domestic 007】
One 、 With special effects , The string will be labeled accordingly :( understand )
1、big() <big> </big> label , Display strings in large font
2、anchor()a label Create anchors , <a name="...."> </a>
3、link() a label Linked <a href="...."> </a>
<script>
re=str.anchor("http://www.baidu.com")
re=str.link("http://www.baidu.com")
</script>4、bold() <b></b> Use bold to display strings
5、blink() Highlighted Show flashing string
6、footcolor Use the specified color to display the string
7、footsize Use the specified size to display the string
<script>
var str="hello, Three Gorges University "
re=str.fontcolor("red")
re=str.fontsize("30px")
</script>8、italics Display the string in italics
9、small() Use small font size to display string
10、sub() Display the string as superscript
11、sup() Display a string as a subscript
12、fixed() Display strings in typewriter text
Two 、 Focus on mastering
1、toUpperCase() Capitalize letters
2、toLocaleLowerCase() Turn the letters into lowercase
Design a method to turn the initial letter into capital by yourself :
<script>
String.prototype.FirstUppserCase=function() { // Add this method to the prototype
ver re = this[0].toUpperCase()
for(var i=1;i<this.length;i++){
re +=this[i]
}
return re
}
// Use :
var str = 'asdfghh'
var re = str.FirstUppserCase()
console.log(re)'Asdfghh'
</script>3、toString() Convert to string
4、valueOf() Returns the original value of the string object
5、indexOf(x,?y) Is to detect whether a string appears , And return the subscript , If there is no return -1;x For the string to query , the second y Is the starting position of the query , The default is zero .
usage :
<script>
// Query the number of occurrences of a character
String.prototype.count1=function(str) {
var re=-1;
var count=0
do{
re=this.indexOf(str,re+1)
if(re!=-1){count++}
}while(re!=-1)
return count
}
var str=" Text content "
var re=str.count1(" The string to query ")
console.log(re)// Number of occurrences
</script>3、 ... and 、 Must master
1、substr(start,num)start Where to start taking ,num Take a few ;start It could be negative , Stands for counting from back to front
<script>
var str = "addlist"
var re1 = str.substr(0,3)
var re2 = str.substr(-3,3)
console.log(re1,re2) //add ist
</script>2、substring(start,?end) Left closed right away from start The subscript begins to take , Take the subscript end The last one of (? Parameters with question marks are optional )
3、split(“ Separator ”) Division , Split the string into an array , Split into an array with the selected delimiter , If this character does not exist in the string , Then the whole string returned is in an array alone .
Specify :
<script>
var str="helxxlo"
var arr=str.split("l")
console.log(arr)// Print ["he","xx","o"]
var arr1=str.split("s")
console.log(arr1)// Print ["helxxlo"]
</script>4、slice() And substring() be similar Get a string fragment
<script>
var str="hello"
var re1=str.substring(0,4)
var re2=str.slice(0,4)
console.log(re1,re2) //hell hell
</script>Four 、 Written test exercise : Put the current web page url The parameter of is resolved to an object
<script>
var url='http://www.hqyj.com/index.html?user=karen&page=10&count=100'
// Resolve to this format {user:"karen",page:"10",count:"100"}
function parseurl(str) {
var querystring=str.split("?")[1]
var arr=querystring.split("&")//["user=karen","page=10","count=100"]
var obj={}
for(var i=0;i<arr.length;i++){
var arr2=arr[i].split("=")
obj[arr2[0]]=arr2[1]
}
return obj
}
var obj=parseurl(url)
console.log(obj)
</script>5、 ... and 、 Add ( Packaging object )
. Syntax is a kind of syntax sugar that refers to data The standard writing is obj[ ]
Why string basic data is not reference data , But it can go through . What methods to use ?
Because when the string basic data uses point syntax , There will be an implicit operation ;
Implicit operation : When all basic data is used as objects , Their point syntax will have one more implicit operation ( Implicitly wrapped as an object )
Specify :
<script>
var str = "jack"
str.age = 20
// Implicit packaging operation
var str = new String("jack")
str.age = 20
console.log(str.age)// Print 20
</script>边栏推荐
- How did the situation that NFT trading market mainly uses eth standard for trading come into being?
- 日志黑名单,真的能帮你省钱!
- Notes 2 of network communication security
- MySQL multi table query internal connection / external connection / self connection
- File upload parsing vulnerability
- For some problems encountered in using crontab, errors are reported /var/spool/cron: permission denied and bash: /usr/bin/chattr: permission denied
- Ant group open source large-scale video infringement positioning data set
- JS -- built in function of data system
- 2. Memory leak and memory overflow
- 41.js -- closure
猜你喜欢

ES6 modular
Graphic and image programming practice course report

Dense Digital Economy: using passwords to "search for pearls in the deep sea"

Unity experiment - gravity hitting the wall

Wechat payment refund PHP

Open source internship | compiler sig internship task is officially released. Welcome to apply!

关于 Visual Studio 2022的安装与使用

MSF Foundation

Unity experiment - control the movement of game objects

WP of the southwest division of the 15th National College Students Information Security Competition (ciscn) 2022
随机推荐
Intranet penetration notes - vulnhub intranet course completion penetration
MSF infiltrates Win2003 with eternal blue
欧拉Talk | 开发者社区体验坦白局7月14日19:30约起
Analysis, capture and simulation attack of Sniffer Pro on ARP Protocol
39.js-- scope
SNMP started
Experimental report on using spark to predict repeat customers
The technology once selected in the top meeting completed the commercialization of ant chain and launched the copyright AI computing engine
MySQL master-slave server configuration experiment centos7
Notes on network communication security -- static routing and experiment
NFTScan 开发者平台推出多链 NFT 数据 Pro API 服务
[BJDCTF2020]Cookie is so stable
BUUCTF 来首歌吧
图形图像编程实践 课程报告
How to solve the "Impossible Triangle" problem of data flow?
MSF基础
Unity experiment - control the movement of game objects
41.js -- closure
ES6 -- Interview Questions
关于 Visual Studio 2022的安装与使用