String trimming


hi,

can me simple task....

 

i have powershell script returns series of strings variables such as:

sql-instance1-<some more text>

sql-instance2-<some more text>

sql-instance3-<some more text>

i want pass of string to, not including last hyphen new variable, trim off <some more text> part, so for example the value of variables 'sql-instance1',  'sql-instance2' , 'sql-instance3'

i have used lastindex of return values after last hyphen struggling returning values last hyphen.

can help?

thanks

lincoln;
i think wants last hyphen:
 
$str = 'sql-instance3-qwerty' $str.substring(0,$str.lastindexof("-")) 

karl

blog: http://unlockpowershell.wordpress.com
book: windows powershell 2.0 bible
e-mail: -join ("6b61726c6d69747363686b65406d742e6e6574"-split"(?<=\g.{2})",19|%{[char][int]"0x$_"})


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607