当前位置:网站首页>JS get the substring of the specified character position and the specified character position interval of the specified string [simple and detailed]
JS get the substring of the specified character position and the specified character position interval of the specified string [simple and detailed]
2022-06-30 10:07:00 【Boyun V】
Js Gets the specified character position of the specified string & Specifies the substring of the character position interval
1. Gets the location of the specified character
-- Sample string
var currentJsonRow.TRADE_TYPE='[1001] Bonded ';
grammar :
character string .substring(" Specify the characters ")
--- Example
currentJsonRow.TRADE_TYPE.substring("[")
result : '[1001] Bonded '
2. Get the substring of the specified character interval
The first one is : prevent IE Incompatible ( I really vomited in some factories ~! Just like IE… The right eyelid jumped again >…<)
For example, get the first [] The substring inside the brackets
Just look at the code below !( Very intuitive !!)
currentJsonRow.TRADE_TYPE.substring(currentJsonRow.TRADE_TYPE.indexOf("[")+1,currentJsonRow.TRADE_TYPE.indexOf("]"))
result : '1001'
The second kind : Regular expressions (YYDS!_ ok )
grammar :
/(?<=\[)(.+?)(?=\])/g
// Get the data in brackets
TRADE_TYPE_NUM = currentJsonRow.TRADE_TYPE.match(/(?<=\[)(.+?)(?=\])/g)[0];
[ The following business code , Don't look _^^]
// Add judgement -- Selected condition increase
if ($("[id$=hidShopID]").val() == "G181") {
if (currentJsonRow.TRADE_TYPE.match(/(?<=\[)(.+?)(?=\])/g) != null || currentJsonRow.TRADE_TYPE.match(/(?<=\[)(.+?)(?=\])/g) != undefined) {
TRADE_TYPE_NUM = currentJsonRow.TRADE_TYPE.match(/(?<=\[)(.+?)(?=\])/g)[0];
} else {
TRADE_TYPE_NUM = currentJsonRow.TRADE_TYPE.split('|')[0];
}
if (TRADE_TYPE_NUM == " All " || TRADE_TYPE_NUM == null || TRADE_TYPE_NUM == undefined) {
xAlert(">>^=^<<");
return;
}
}

边栏推荐
- Abstract classes and interfaces
- Flutter的特别之处在哪里
- Mysql database learning 1
- 栈题目:字符串解码
- Datatabletomodellist entity class
- [Ubuntu redis installation]
- Appium automation test foundation - 12 Introduction to appium automated testing framework
- What makes flutter special
- Critical applications and hyper converged infrastructure: the time has come
- 【JVM】G1垃圾回收器简述
猜你喜欢

安装和使用

C语言实现扫雷游戏,附详解及完整代码

MIT-6874-Deep Learning in the Life Sciences Week5

机械臂速成小指南(五):末端执行器

How to build a private cloud and create a hybrid cloud ecosystem?

Shell script multi loop experiment

Applying applet container technology to IOT ecological construction

Eight sorts (I)

NTP of Prometheus monitoring_ exporter

Theme Studio
随机推荐
李沐《动手学习深度学习》d2lbook环境搭建
11. customize hooks
7.手机登陆功能开发
Xlnet (generalized autorefressive trainingfor language understanding) paper notes
Oracle cross database replication data table dblink
Critical applications and hyper converged infrastructure: the time has come
LVS load balancing
OSError: [Errno 28] No space left on device
Appium automation test foundation - 12 Introduction to appium automated testing framework
C语言实现扫雷游戏,附详解及完整代码
Installing Oracle database process in windows2007 on VM
G-Code 详解
Use and description of event delegation
Read the difference and connection between hyperfusion and private cloud
Redis + MySQL implements the like function
MySQL optimization
MIT-6874-Deep Learning in the Life Sciences Week5
Hospital integration platform super fusion infrastructure transformation scheme
Eight sorts (I)
P. Summary of NP, NPC, NP hard and other issues