如何在javascript中从特定单词中拆分字符串?

时间:2018-04-04 05:38:58

标签: javascript jquery

public function Confirmar() {
   print_r($this->session->userdata());
}

我想从 \ Attachment 中拆分字符串并获取字符串的其余部分,例如 \ Attachment \ images \ indofab.png 。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

对于此特定字符串,您可以使用:

var arr=test.split("Indofebweb");
var restString=arr[1];  //-----contains string \Attachment\images\indofab.png

您可以使用split()函数创建自己的逻辑。

更新的代码----尝试这个----低于HTML

<!DOCTYPE html>
<html>
<body>

<p> a string display :</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var str = "c:\\Project\\Indofebweb\\Attachment\\images\\indofab.png";; 
    var arr=str.split("Indofebweb");
    document.getElementById("demo").innerHTML = arr[1];
}
</script>

</body>
</html>

答案 1 :(得分:0)

使用str.match()

    path.match(/\\Attachment.*/);

这将返回包括&#34; \ Attachment&#34;之后的所有内容。请记住,需要转义反斜杠。

相关问题