Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Many thanks to you for putting it together and to the forum members for taking the time to post their replies and give their time to help others. Their isn't another site that can touch it..."

Geography

Where in the world do Tek-Tips members come from?

Back tick not working as escape character

58sniper (MIS)
22 Jan 10 18:35
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 --> PowerShell

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:


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.
http://www.ucblogs.net/blogs/exchange/
 

58sniper (MIS)
23 Jan 10 19:00
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.
http://www.ucblogs.net/blogs/exchange/
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close