If you are posting PowerShell code sample and want to format the text nicely, there’s an on-line high-lighter tool that will do this for you available here.
This formatting tool is pretty nice. Consider the following script (from http://pshscripts.blogspot.com):
# Parse and TryParse static methods on Int64 type # Sample using PowerShell # Thomas Lee - tfl@psp.co.uk
# Create an int64 and two strings $i=new-object system.int64 "varable `$i created - type is {0}" -f $i.GetTypeCode() $s1="1234" $s2="12345678934212321212"
# Use the Parse static method on S1 that WILL work OK $i=[system.int64]::parse($s1) "The integer `$i={0} - parsed OK as Int64" -f $s1 ""
# Use the TryParse static method with small and too large a number $result=[system.int64]::tryparse($s1,[ref] $i) "The string `"{0}`" parsed correctly as an int64: {1}" -f $s1,$result $result=[system.int64]::tryparse($s2,[ref] $i) "The string `"{0}`" parsed correctly as an int64: {1}" -f $s2,$result
Using the online Highligher tool creates HTML you can cut/past into your web site, thus you end up with something that looks like this:
- # Parse and TryParse static methods on Int64 type
- # Sample using PowerShell
- # Thomas Lee - tfl@psp.co.uk
- # Create an int64 and two strings
- $i=new-object system.int64
- "Variable `$i created - type is {0}" -f $i.GetTypeCode()
- $s1="1234"
- $s2="12345678934212321212"
- # Use the Parse static method on S1 that WILL work OK
- $i=[system.int64]::parse($s1)
- "The integer `$i={0} - parsed OK as Int64" -f $s1
- ""
- # Use the TryParse static method with small and too large a number
- $result=[system.int64]::tryparse($s1,[ref] $i)
- "The string `"{0}`" parsed correctly as an int64: {1}" -f $s1,$result
- $result=[system.int64]::tryparse($s2,[ref] $i)
- "The string `"{0}`" parsed correctly as an int64: {1}" -f $s2,$result
The Highlighter tool can create the HTML fragement with or without a link to a CSS style sheet. In using this tool with Live Writer to produce this blog posting there seems to be little difference. To demonstrate this point, here’s the code without a CSS link:
- # Parse and TryParse static methods on Int64 type
- # Sample using PowerShell
- # Thomas Lee - tfl@psp.co.uk
- # Create an int64 and two strings
- $i=new-object system.int64
- "varable `$i created - type is {0}" -f $i.GetTypeCode()
- $s1="1234"
- $s2="12345678934212321212"
- # Use the Parse static method on S1 that WILL work OK
- $i=[system.int64]::parse($s1)
- "The integer `$i={0} - parsed OK as Int64" -f $s1
- ""
- # Use the TryParse static method with small and too large a number
- $result=[system.int64]::tryparse($s1,[ref] $i)
- "The string `"{0}`" parsed correctly as an int64: {1}" -f $s1,$result
- $result=[system.int64]::tryparse($s2,[ref] $i)
- "The string `"{0}`" parsed correctly as an int64: {1}" -f $s2,$result
No comments:
Post a Comment