header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Trim variable data (other than spaces)?
Last Post 30 Sep 2008 10:35 PM by jcossota. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jcossotaUser is Offline
New Member
New Member
Posts:6
Avatar

--
30 Sep 2008 10:19 PM  

Looking for a way to grab the first character of a value and assign it to a value.
Can't seem to get the language right... here is what I have as an example:

$strFname = "Jason"
$strFnameInit = $strFname.left(1)

I want $strFnameInit to be assigned "J" here.
When I run the code I get the following error in PowerGUI:

Method invocation failed because [System.String] doesn't contain a method named 'left'.

ShayUser is Offline
Basic Member
Basic Member
Posts:281
Avatar

--
30 Sep 2008 10:30 PM  

You can always use the substring() string method:

PS > $strFnameInit = $strFname.substring(0,1)
PS > $strFnameInit
J

Or using array notation:

PS > $strFnameInit = $strFname[ 0 ]
PS > $strFnameInit
J

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
jcossotaUser is Offline
New Member
New Member
Posts:6
Avatar

--
30 Sep 2008 10:35 PM  

Perfect, thanks for your speedy response Shay!

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer