none
Little question about ü,ö,ä and other special signs RRS feed

  • Question

  • Hello everyybody!

    ive got a little question. but couldnt found anything about it ( well im short on time too)

    working on win 7 ultimate

    powershel 2.0

    exchange shell installed

     

    Ive got a string which is created from a Firstname and a Lastname. like: Edward Rüdisüli his shortname will be --> ERüDIS

    so his shortname contains a ü! well i dont like this ü,ö,ä signs. thats cause i would like to replace them wit ä->ae,ö->eo,ü ->ue.

    well that ist a big problem. buuutt i dont like !,.-?_|/ and all this other special things either. but how can i make a if query for al this signs?

    like:

    if($shortname -contains ........){ write-host 'Special signs arnt allowed!' }

     

    how can i do that easly?

     

    Thank you verry much. and im realy sorry for my bad english.

    Thursday, May 5, 2011 1:53 PM

Answers

  • Not sure if you would call it "easy", but here's a function that should work.  It takes the name, splits it into a character array, then test the [int] value of each character.  This set of tests will return $false if the [int] of any character is within the set of ranges that don't correspond to the characters 0-9, a-z, or A-Z, otherwise it will return $true.

     

    function test-name {
    param ([string]$name)
    [char[]]$name | foreach-object {
    if ([int]$_ -lt 48){$false;break}
    if ([int]$_ -gt 57 -and [int]$_ -lt 65){$false;break}
    if ([int]$_ -gt 90 -and [int]$_ -lt 97){$false;break}
    if ([int]$_ -gt 122){$false;break}
    }
    $true
    }

    test-name "ERüDIS"
    False

    If you want to modify it, you can get a quick ascii table like this:

    0..255 | foreach-object  {[string]$_ + " = " + [char]$_}


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Monday, May 9, 2011 11:48 PM
    Moderator

All replies

  • Not sure if you would call it "easy", but here's a function that should work.  It takes the name, splits it into a character array, then test the [int] value of each character.  This set of tests will return $false if the [int] of any character is within the set of ranges that don't correspond to the characters 0-9, a-z, or A-Z, otherwise it will return $true.

     

    function test-name {
    param ([string]$name)
    [char[]]$name | foreach-object {
    if ([int]$_ -lt 48){$false;break}
    if ([int]$_ -gt 57 -and [int]$_ -lt 65){$false;break}
    if ([int]$_ -gt 90 -and [int]$_ -lt 97){$false;break}
    if ([int]$_ -gt 122){$false;break}
    }
    $true
    }

    test-name "ERüDIS"
    False

    If you want to modify it, you can get a quick ascii table like this:

    0..255 | foreach-object  {[string]$_ + " = " + [char]$_}


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Monday, May 9, 2011 11:48 PM
    Moderator
  • Thank you very much that is something what i searched for!

    i hope its oke, when i take it and implement it in my code! =)

     

    its great to have such a community here! =)

    Wednesday, May 11, 2011 6:29 AM