Solved

extract the number from a string

Posted on 2014-04-28
2
573 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
Comment Utility
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
Comment Utility
You need
$str.substring($str.length -2, 2)

where $str is your string.

LE: too slow :)

HTH,
Dan
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Synchronize a new Active Directory domain with an existing Office 365 tenant
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

10 Experts available now in Live!

Get 1:1 Help Now