Sylnois
 New Member Posts:11

 |
| 11 Aug 2010 04:56 AM |
|
Hey guys Have some trubbles. Why this donesn't work:
$Ip = $_
$i = 0
do{
$i = $i +1
}while($Ip.substring($i, $i+1) -ne ';')
Heres the error:
Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string.
Parameter name: length"
At C:\Users\username\Desktop\Powershell\hallo.ps1:29 char:23
+ }while($Ip.substring <<<< ($i, $i+1) -ne ';')
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Thanks Sylnois
|
|
|
|
|
Marco Shaw (MVP)
 Veteran Member Posts:1642

 |
| 11 Aug 2010 05:03 AM |
|
I think what has you here, is there's a common misconception on what substring() does. I even forget... SubString(starting_position,number_of_positions_to_read) So, substring(1,1), gets the starting starting in position 1, and gets the following character only (1). |
|
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com |
|
|
Sylnois
 New Member Posts:11

 |
| 11 Aug 2010 05:16 AM |
|
Ohh.. I search a command like this:
$Ip.COMMAND([Position_From], [Posistion_To])
Do you know a command, that can do this.
Sylnois
|
|
|
|
|
Marco Shaw (MVP)
 Veteran Member Posts:1642

 |
| 11 Aug 2010 05:23 AM |
|
Substring works, you just need to do something like this (I think): substring($i,1) |
|
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com |
|
|
Sylnois
 New Member Posts:11

 |
| 11 Aug 2010 05:41 AM |
|
I just managed it. I'm so stupid :D But thanks a lot. Can be closed.
|
|
|
|
|
Marco Shaw (MVP)
 Veteran Member Posts:1642

 |
| 11 Aug 2010 05:43 AM |
|
Not stupid... We are all learning some thing or other. |
|
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com |
|
|