Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Back tick not working as escape character

Status
Not open for further replies.

58sniper

MIS
Apr 25, 2004
9,152
US
So I'm importing some data from CSV and trying to do some cool stuff. But I'm noticing the back tick (`) is not properly escaping special characters.
Code:
ForEach ($user in $users){
	$username = $user.FirstName+"."+$user.LastName
	$upn = $username+"@mydomain.com"
	$state = $user.St
	$party = $user.Party
	$firstname = $user.FirstName
	$lastname = $user.LastName
	$display = "Gov. $FirstName $LastName `[$Party-$State`]"
	write-host $username $upn $display
}

I end up with the trailing "]" at the beginning of the line (instead of the first character), except on the last line:
governors2.png


I have tracked the problem down to the $display= line. The data in the other variables is fine. It doesn't matter whether I use [], (), <>, or {}, I get the same results. It's not escaping those characters. If I remove those characters, things display correctly. I just can't seem to get around this.

Ideas?

Pat Richard MVP
Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.
 
Resolved - turns out some hidden line breaks in the csv were to blame. They didn't show in Notepad or Excel.

Pat Richard MVP
Plan for performance, and capacity takes care of itself. Plan for capacity, and suffer poor performance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top