Monday, January 9, 2012

Creating Multiline Strings

 

PowerTip of the Day, from PowerShell.com:

You probably know what this line produces:

'Hello' * 12

Right, you get 12 times the string you submitted. If you wanted new lines instead, a minor adjustment will do the job:

,'Hello' * 12

The comma puts the string into an array, and when you multiply arrays, you get additional array elements. Simply use Out-String to turn that into a single multi-line string:

PS> $text = ,'Hello' * 12

PS> $text.GetType().FullName

System.Object[]

PS> $text.Count

12

PS> $text = ,'Hello' * 12 | Out-String

PS> $text.GetType().FullName

System.String

PS> $text

Hello

Hello

Hello

(...)

 

Thanks

1 comment:

  1. Hello Aman. I just wanted to let you know about a very useful online localization tool https://poeditor.com/ you can try when dealing with strings translation. Due to its simple and user-friendly interface, it can make things easier for both translators and developers. Give it a shot, maybe it can be a helpful tool. Cheers!

    ReplyDelete

Note: Only a member of this blog may post a comment.