当前位置:网站首页>Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
2022-06-30 09:36:00 【泊云V】
Js获取指定字符串指定字符位置&指定字符位置区间的子串
1.获取指定字符的位置
--示例字符串
var currentJsonRow.TRADE_TYPE='[1001]保税';
语法:
字符串.substring("指定字符")
---例子
currentJsonRow.TRADE_TYPE.substring("[")
结果: '[1001]保税'
2.获取指定字符区间的子串
第一种:防止IE不兼容使用的(有些工厂我真的吐了~!就喜欢IE…右眼皮又跳了>…<)
比如获取首次[]中括号的里面的子串
直接看下面的代码吧!(直观的很!!)
currentJsonRow.TRADE_TYPE.substring(currentJsonRow.TRADE_TYPE.indexOf("[")+1,currentJsonRow.TRADE_TYPE.indexOf("]"))
结果: '1001'
第二种:正则表达式(YYDS!_好吧)
语法:
/(?<=\[)(.+?)(?=\])/g
//获取中括号里面的数据
TRADE_TYPE_NUM = currentJsonRow.TRADE_TYPE.match(/(?<=\[)(.+?)(?=\])/g)[0];
[下面的自己的业务代码,不用看_^^]
//添加判断--选择的条件增加
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 == "全部" || TRADE_TYPE_NUM == null || TRADE_TYPE_NUM == undefined) {
xAlert(">>^=^<<");
return;
}
}

边栏推荐
- 李沐《动手学习深度学习》d2lbook环境搭建
- MIT-6874-Deep Learning in the Life Sciences Week6
- 关于字符串的split和join操作
- Quick completion guide for mechanical arm (V): end effector
- Installing Oracle database process in windows2007 on VM
- Use and description of event delegation
- 3. integrate eslint and prettier
- 近期学习遇到的比较问题
- Difference between bow and cbow
- Force buckle 428 Serialize and deserialize n-tree DFS
猜你喜欢

Cobbler Automated Deployment

Network based dynamic routing protocol (OSPF)

云技能提升好伙伴,亚马逊云师兄今天正式营业

Right click to open CMD (command line)

9.缓存优化

Force buckle 428 Serialize and deserialize n-tree DFS

Plan the IT technology route for the new year? Let's learn about Gartner infrastructure hype cycle

NFS shared services

Principle and implementation of small program hand-held bullet screen (uni APP)
![[new book recommendation] mongodb performance tuning](/img/2c/e5a814df4412a246c703ca548a4f68.png)
[new book recommendation] mongodb performance tuning
随机推荐
[new book recommendation] DeNO web development
GNN动手实践(二):复现图注意力网络GAT
MIT-6874-Deep Learning in the Life Sciences Week6
ABAP-时间函数
Appium自动化测试基础 — 12.APPium自动化测试框架介绍
Forrester senior analyst: five important trends in the development of the hyper convergence market
Machine learning note 9: prediction model optimization (to prevent under fitting and over fitting problems)
Redis docker master-slave mode and sentinel
NFS shared services
[Ubuntu redis installation]
单片机 MCU 固件打包脚本软件
How can we have high performance and simple agility in the enterprise cloud on oracle?
NTP of Prometheus monitoring_ exporter
Deberta (decoding enhanced Bert with distinguished attention)
Theme Studio(主题工作室)
Redis docker master-slave mode and sentinel
MySQL optimization
Installing Oracle database process in windows2007 on VM
Input limit input
Network based BGP