0

I have the following string. I want to get everything before the character |

'abc eff 23 aaa|C:\\WINDOWS|\\Device\\Harddisk\\Parti'

My output should be like 'abc eff 23 aaa'

How do i get it.. Please help me with this

Jung-suk
  • 172
  • 2
  • 12
  • 3
    I see you've posted several questions now, you should get used to researching before posting a new question. Here's a [blog post](https://techblog.bozho.net/tips-for-identifying-and-debugging-problems/) from Bozho on how debug problems from your code, notice how asking a question is one of the last steps... – RichieV Sep 23 '20 at 14:02
  • Yeah i did.. but couldn't able to find the related post before.. i'll go through that "blog post". Thank you @RichieV – Jung-suk Sep 23 '20 at 14:08
  • 1
    @Jung-suk - for the record, i found the duplicate question by copying your question title into google. – Sayse Sep 23 '20 at 14:14

3 Answers3

7
'abc eff 23 aaa|C:\\WINDOWS|\\Device\\Harddisk\\Parti'.split('|')[0]
Rorepio
  • 332
  • 1
  • 4
  • 16
0

You would use the built-in 'split' function as such:

'abc eff 23 aaa|C:\\WINDOWS|\\Device\\Harddisk\\Parti'.split('|')[0]

Here is the documentation on how it works if you are curious.

NTSwizzle
  • 101
  • 6
0

There are 2 methods you can use here either use string.split('|')[0] or string[:string.find('|')] (as a string is an array you can do this as well)

rigons99
  • 109
  • 3