A
A
Alexander2018-12-05 11:56:00
PowerShell
Alexander, 2018-12-05 11:56:00

How to remove a piece of a string after a certain character?

Good afternoon, please help, it is necessary to remove the characters after the # sign in the xml file. The number of characters is always the same.
Example:
<ID>df1eaa47-6d9b-11e1-8016-000e0c4358bd#efc75a38-1e91-11e7-aacc-001d607884abID>
You need to remove the characters after # (including #) to get this:
<ID>df1eaa47-6d9b-11e1-8016- 000e0c4358bdID>
$str = Get-Content ''
$str.Split("ID>")[-1]
But that's not correct

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ApeCoder, 2018-12-05
@ApeCoder

(gc $fileName -raw) -replace '#.*',''

A
Andrew AT, 2018-12-05
@AAT666

$obj = "<Ид>df1eaa47-6d9b-11e1-8016-000e0c4358bd#efc75a38-1e91-11e7-aacc-001d607884abИд>"
([regex]::matches($obj,"(<Ид>.*)#.*"))[0].groups[1].value + "Ид>"

S
strangerror, 2018-12-13
@strangerror

$str = '<Ид>df1eaa47-6d9b-11e1-8016-000e0c4358bd#efc75a38-1e91-11e7-aacc-001d607884abИд>'
$str = $str.remove($str.indexof('#'))+"Ид>"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question