Would like to know how to remove space when combining string variables in below code. Cause when I count the length of $myname, it will also include the space length
$myname = $firstname + " " + $lastname
Use replace and regex to replace spaces with nothing before you do the length function. Last $myname is just to prove we didn't actually remove spaces in the variable while getting the length.
$LastName = "Smith"
$FirstName = "John"
$myname = $Firstname + " " + $Lastname
$myname
($myname -replace "\s","").length
$myname
Output
John Smith
9
John Smith
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With