Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Select first 16 characters in a string

Reply
 
Old 11-11-2008   #1 (permalink)
Steven


 
 

Select first 16 characters in a string

I need to figure out how to take a string and pick out the first 16
characters of that string to be used in a pattern match later. Anyone
have any suggestions on how to select a certain number of characters
(digits, letters, and even white space)?

My System SpecsSystem Spec
Old 11-11-2008   #2 (permalink)
Steven


 
 

Re: Select first 16 characters in a string

Actually figured it out for myself for once (how bout that).

<string> -match '.{1,16}'

Steven wrote:
Quote:

> I need to figure out how to take a string and pick out the first 16
> characters of that string to be used in a pattern match later. Anyone
> have any suggestions on how to select a certain number of characters
> (digits, letters, and even white space)?
My System SpecsSystem Spec
Old 11-11-2008   #3 (permalink)
PaulChavez


 
 

RE: Select first 16 characters in a string

You can use the substring method on a string.

63# "sixteen character string".Substring(0,16)
sixteen characte

-paul

"Steven" wrote:
Quote:

> I need to figure out how to take a string and pick out the first 16
> characters of that string to be used in a pattern match later. Anyone
> have any suggestions on how to select a certain number of characters
> (digits, letters, and even white space)?
>
My System SpecsSystem Spec
Old 11-11-2008   #4 (permalink)
Shay Levy [MVP]


 
 

Re: Select first 16 characters in a string


PS > $s = "abcdefghijklmnopqrstuvwxyz"
PS > $s[0..15]

a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p




---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar



S> I need to figure out how to take a string and pick out the first 16
S> characters of that string to be used in a pattern match later.
S> Anyone have any suggestions on how to select a certain number of
S> characters (digits, letters, and even white space)?
S>


My System SpecsSystem Spec
Old 11-12-2008   #5 (permalink)
Steven Peck


 
 

Re: Select first 16 characters in a string


Based on your initial question, I would have thought this link a better match:
http://www.microsoft.com/technet/scr...vert/left.mspx

$a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$a = $a.substring(0,16)


Steven Peck
http://www.blkmtn.org/powershell


"Steven" wrote:
Quote:

> Actually figured it out for myself for once (how bout that).
>
> <string> -match '.{1,16}'
>
> Steven wrote:
Quote:

> > I need to figure out how to take a string and pick out the first 16
> > characters of that string to be used in a pattern match later. Anyone
> > have any suggestions on how to select a certain number of characters
> > (digits, letters, and even white space)?
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Remove characters in a string VB Script
How to Randomize characters in a string VB Script
Replacing Multiple Characters In A String PowerShell
problems with $var | select-string -pattern $string -q PowerShell
Removing characters from a string PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46