Click here to Skip to main content
15,885,365 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031626-May-19 0:23
Member 1379031626-May-19 0:23 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff26-May-19 0:50
professionalBillWoodruff26-May-19 0:50 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031626-May-19 1:52
Member 1379031626-May-19 1:52 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff26-May-19 18:57
professionalBillWoodruff26-May-19 18:57 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031626-May-19 19:01
Member 1379031626-May-19 19:01 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff26-May-19 21:16
professionalBillWoodruff26-May-19 21:16 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031627-May-19 0:33
Member 1379031627-May-19 0:33 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff27-May-19 0:46
professionalBillWoodruff27-May-19 0:46 
C# 8 will allow you to use expression bodies that return values in a 'switch statement; I am not yet comfortable with this very different style:
int offset = '9' + '0';

public char EncodeChar(char ch)
{
    return ch switch
    {
        Char c when Char.IsDigit(ch) =>
            ((char) (offset - ch)),

        Char c when Char.IsUpper(ch) =>
            ch == 'Z' ? 'Y' : ((char)(ch - 1)),

        Char c =>
            ch == 'z' ? 'a' : ((char) (ch + 1))
    };
}

public string Encode3(string source)
{
    StringBuilder sb = new StringBuilder();

    foreach (char ch in source)
    {
        sb.Append(EncodeChar(ch));
    }

    return sb.ToString();
}

«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

GeneralRe: How to replace every different char with another given char Pin
Member 1379031627-May-19 0:56
Member 1379031627-May-19 0:56 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff27-May-19 2:39
professionalBillWoodruff27-May-19 2:39 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031628-May-19 8:29
Member 1379031628-May-19 8:29 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031628-May-19 20:19
Member 1379031628-May-19 20:19 
GeneralRe: How to replace every different char with another given char Pin
kalberts29-May-19 4:49
kalberts29-May-19 4:49 
GeneralRe: How to replace every different char with another given char Pin
OriginalGriff26-May-19 1:33
mveOriginalGriff26-May-19 1:33 
GeneralRe: How to replace every different char with another given char Pin
Member 1379031626-May-19 1:51
Member 1379031626-May-19 1:51 
GeneralRe: How to replace every different char with another given char Pin
OriginalGriff26-May-19 5:13
mveOriginalGriff26-May-19 5:13 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff26-May-19 1:51
professionalBillWoodruff26-May-19 1:51 
GeneralRe: How to replace every different char with another given char Pin
OriginalGriff26-May-19 3:09
mveOriginalGriff26-May-19 3:09 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff26-May-19 22:08
professionalBillWoodruff26-May-19 22:08 
GeneralRe: How to replace every different char with another given char Pin
OriginalGriff26-May-19 22:22
mveOriginalGriff26-May-19 22:22 
GeneralRe: How to replace every different char with another given char Pin
BillWoodruff26-May-19 22:55
professionalBillWoodruff26-May-19 22:55 
GeneralRe: How to replace every different char with another given char Pin
kalberts29-May-19 4:52
kalberts29-May-19 4:52 
GeneralRe: How to replace every different char with another given char Pin
OriginalGriff29-May-19 5:08
mveOriginalGriff29-May-19 5:08 
GeneralRe: How to replace every different char with another given char Pin
lmoelleb26-May-19 8:40
lmoelleb26-May-19 8:40 
AnswerRe: How to replace every different char with another given char Pin
Luc Pattyn25-May-19 19:16
sitebuilderLuc Pattyn25-May-19 19:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.