Wanted to trim suffix from my string using powershell scripting?
hi,
i have string "abcdefg_control" . wanted return "abcdef" i.e remove suffix "_control" . also, tried use trimend() , split() in powershell script shell prompt throwing errors these methods. there other way use these .net framework methods in power shell? please let me know way use these .net framework methods in powershell , solve problem of removing suffix.
thanks,
anirudh
hi
i tried first example powershell throwing following error:
"method invocation failed because [system.io.fileinfo] doesn't contain method named 'indexof'.
@ d:\ariba\scripts\my_script_control\newbalancingcontrolfile.ps1:62 char:56"
i have used:
$str=$actualfile.substring(0,$actualfile.indexof("."))
where $actualfile "remittance.csv"
thanks
ps > [io.path]::getfilenamewithoutextension("file.txt") file ps > $actualfile.substring(0,$actualfile.indexof(".")) file ps > $str = $actualfile.substring(0,$actualfile.indexof(".")) ps > $str file
simple : $actualfile.basename
ps > $file = gi c:\windows\win.ini ps > $file.gettype().fullname system.io.fileinfo ps > $file.basename win
Windows Server > Windows PowerShell
Comments
Post a Comment