且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在java脚本中拆分字符串并获取子字符串。

更新时间:2023-02-18 20:03:23

  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.