Reputation: 21
I'm working on a function, which works fine except when I try to use the Substring method.
Once I add .substring(#,#) to any of the strings in my function, other strings seem to break.
Am I doing something wrong? I can't figure out a way to use substring() in a function without it breaking the function.
If I run my code outside of a function, everything seems to work fine.
function Get-String ($string1, $string2)
{
return($string1.substring(0,1) + $string2)
}
Get-String("One"+"Two")
I'd expect this function to return "OTwo" It returns "O"
Replacing the variables with string literals resolves the issue.
Upvotes: 0
Views: 49
Reputation: 21
Per Theo's comment: changed
Get-String("One"+"Two")
to
Get-String "One" "Two"
and everything works perfectly now.
Upvotes: 2