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

3
  • 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 from Bozho on how debug problems from your code, notice how asking a question is one of the last steps... Commented Sep 23, 2020 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 Commented Sep 23, 2020 at 14:08
  • 1
    @Jung-suk - for the record, i found the duplicate question by copying your question title into google. Commented Sep 23, 2020 at 14:14

3 Answers 3

7
'abc eff 23 aaa|C:\\WINDOWS|\\Device\\Harddisk\\Parti'.split('|')[0]
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.