?
Solved

extract the number from a string

Posted on 2014-04-28
2
Medium Priority
?
610 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A procedure for exporting installed hotfix details of remote computers using powershell
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ā€¦
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrā€¦

801 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