PoshCode Archive  Artifact [15a8373aba]

Artifact 15a8373abaf0ebb3ec7cceee0186dc0df620d8f9f0ef9752c20f25b5f68a15bc:

  • File Get-StringRange.ps1 — part of check-in [f5a5a4f8f9] at 2018-06-10 12:56:40 on branch trunk — Works like the integer range operator “..”, but for characters. (user: halr9000 size: 989)

# encoding: ascii
# api: powershell
# title: Get-StringRange
# description: Works like the integer range operator “..”, but for characters.
# version: 0.1
# type: function
# author: halr9000
# license: CC0
# function: Get-CharRange
# x-poshcode-id: 1216
# x-archived: 2009-10-25T10:44:44
#
#
## Works great for a..f or g..a
## BUT WEIRD for Z..a or A..a or anything non-latin
function Get-CharRange ( [char]$Start, [char]$End ) {
	[char[]]($Start..$End)
}

## Cleaner output. Try Get-LetterRange A z  vs. Get-CharRange A z
## And international. ## Get-LetterRange 0x0370 0x03FF Greek
## You just specify the character set by name, anything from Arabic and Armenian,
## Bengali, Cherokee, Cyrillic, to Greek, Hebrew, Mongolian, and so on.
## http://msdn.microsoft.com/en-us/library/20bw873z.aspx
function Get-LetterRange ( [char]$Start, [char]$End, [string]$charset = "BasicLatin" ) {
 [char[]]($Start..$End) | Where { $_ -match "(?=\p{Is$charset})\p{L}" }
}