Solved

extract the number from a string

Posted on 2014-04-28
2
580 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
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 34

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now