Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

extract the number from a string

Posted on 2014-04-28
2
Medium Priority
?
615 Views
Last Modified: 2014-04-28
Hi,

if I had a variable which consisted of a string like this $a = "abc-wertr01" sometimes the lenght of the sting can be longer. How can I extract the last two characters from the string?

I want to increase the number in the string by 1.. and to do that I need to turn that part of the string into an integer

Thanks

$TempName = "abc-wertr01"
$a = $TempName
$b = $a.Length
$c = $b - 2
$d = $a.substring($c)
$e = [INT] $d
$f = "{0:D2}" -f $e
$e++

Open in new window

0
Comment
Question by:patelbg2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
patelbg2001 earned 0 total points
ID: 40026976
worked it out
$TempName = "abc-wertr01"
$a = $TempName
$b = $a.substring($a.length -2, 2)

Open in new window

0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40026985
You need
$str.substring($str.length -2, 2)

where $str is your string.

LE: too slow :)

HTH,
Dan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question