如何在java脚本中拆分字符串并获取子字符串。 [英] how to split the string and get substring in java script.

查看:76
本文介绍了如何在java脚本中拆分字符串并获取子字符串。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



我的字符串如下:



LDAP:// XYZ_2010_dev1 / OU =样本,OU =测试,DC = 2010dev1,DC = com



现在我想要字符串中唯一的这一部分:



OU =样本,OU =测试,DC = 2010dev1,DC = com



如何使用java脚本获取此内容?



先谢谢。

解决方案

  var  str = '  LDAP:// XYZ_2010_dev1 / OU = sample,OU = test,DC = 2010dev1,DC = com'
delimiter = ' /'
start = 3
tokens = str.split(delimiter).slice(start),
result = tokens.join(定界符);
提醒(结果);



这样做:)



-KR


如果您希望更改OU值,那么

1)使用 indexOf 找到字符串中的第一个OU

2)使用 subString 来解析从步骤1中找到的位置到字符串末尾的字符串。


正则表达式 [ ^ ]可以胜任。


Hi.

I have a string like:

"LDAP://XYZ_2010_dev1/OU=sample,OU=test,DC=2010dev1,DC=com"

Now I want the only this part from the string:

OU=sample,OU=test,DC=2010dev1,DC=com

How to get this using java script?

Thanks in Advance.

解决方案

var str = 'LDAP://XYZ_2010_dev1/OU=sample,OU=test,DC=2010dev1,DC=com',
delimiter = '/',
start = 3,
tokens = str.split(delimiter).slice(start),
result = tokens.join(delimiter);
alert(result);


This will do :)

-KR


If you expect the OU values to change, then
1) locate the first OU in the string using indexOf
2) use subString to parse string from the location found in step 1 to the end of the string.


A regular expression[^] would do the job.


这篇关于如何在java脚本中拆分字符串并获取子字符串。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆