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

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2