-4
[
    { 
    docPath: "c:\Project\Indofebweb\Attachment\images\indofab.png",
    }
]

I want to split the string from \Attachment and get the rest of the string e.g \Attachment\images\indofab.png . How can I do this?

Tejas Valand
  • 33
  • 1
  • 13
  • try using regular expressions – Yash Karanke Apr 04 '18 at 05:40
  • 1
    Here's two links to get you started: [`string.split`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) & [`string.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf). – Alexander Nied Apr 04 '18 at 05:41
  • if `c:\Project\Indofebweb\\` is a constant path try `path = test.replace('c:\Project\Indofebweb','');` – Azad Apr 04 '18 at 05:42
  • 1
    Here's another one: [`string.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) – Robby Cornelissen Apr 04 '18 at 05:42
  • Possible duplicate of [How do I split a string, breaking at a particular character?](https://stackoverflow.com/questions/96428/how-do-i-split-a-string-breaking-at-a-particular-character) – ochs.tobi Apr 04 '18 at 05:47

2 Answers2

0

For this particular string you can use :

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

You can make your own logic using split() function.

UPDATED CODE----TRY THIS----BELOW 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>
akash verma
  • 159
  • 1
  • 15
0

use str.match()

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

this will return everything after and including "\Attachment". Keep in mind that backslashes need to be escaped.

Bernhard
  • 1,852
  • 11
  • 19