Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex Replace
#1
Hi,

I would like to know the equivalent code for the PowerShell code below, I use this method a lot

The C# method is as follows
https://learn.microsoft.com/en-us/dotnet...em-string)

PowerShell code is a little more elegant to implement, However, sometimes I need to implement it in QM

Thanks in advance for any advice and help
david
 
Code:
Copy      Help
$s = @'
bbbbb2
aaaaa4


@hello
hello

@world
world
'@
$a = 'ABC'

[regex]::Replace($s, '(?s)^[^@]+', {
        $av = $args.Value
        if ([string]::IsNullOrEmpty($av.Trim())) { return $av }
        [int[]]$num = [regex]::Matches($av, '\d+').Value
        $n = 1
        while ($true)
        {
            if ($num -ne $null -and $num.Contains($n)) { $n++ }
            else { break }
        }
        return "{0}`r`n$a$n`r`n`r`n" -f $av.TrimEnd()
    })
#2
The only problem with the powershell code, even if it is packaged into EXE files using QM, it will generate temporary powershell files, which is not very secure  Smile

I'm not very proficient in C# either, can someone provide an equivalent LA code?


Forum Jump:


Users browsing this thread: 1 Guest(s)