dras
August 21, 2022, 10:22pm
1
Hello I have a string which I want to convert with regex.
$var= b8mysq364kfauhocn9lxwezt7ridp
needs to be : X0b8 X0mys X0q3 X064 X0kf X0au X0ho X0cn X09l X0xw X0ez X0t7 X0ri X0dp
so starting before index one whit “X0” and after a space. And then begore each 2e character again “X0” and a space after.
Who knows how todo this?
Thanks,
Andreas
Olaf
August 21, 2022, 10:50pm
2
Andreas,
Welcome to the forum.
I googled “Powershell split string every second character ” and this was the first hit:
Using this as an inspiration I pieced this together:
$var = 'b8mysq364kfauhocn9lxwezt7ridp'
($var -split '(..)' -ne '' |
ForEach-Object {
'X0' + $_
} ) -join ' '
… and the output is this:
X0b8 X0my X0sq X036 X04k X0fa X0uh X0oc X0n9 X0lx X0we X0zt X07r X0id X0p
And BTW your string has an odd number of characters.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
How to format code in PowerShell.org <---- Click
dras
August 21, 2022, 11:21pm
3
wonderfull thanks I didnt find it