Click here to Skip to main content
15,895,799 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help With Code Pin
Ravi Bhavnani20-Nov-09 14:01
professionalRavi Bhavnani20-Nov-09 14:01 
GeneralRe: Help With Code Pin
aaffbbww20-Nov-09 14:08
aaffbbww20-Nov-09 14:08 
GeneralRe: Help With Code Pin
Ravi Bhavnani20-Nov-09 17:06
professionalRavi Bhavnani20-Nov-09 17:06 
AnswerRe: Help With Code Pin
Luc Pattyn20-Nov-09 14:21
sitebuilderLuc Pattyn20-Nov-09 14:21 
GeneralRe: Help With Code Pin
aaffbbww20-Nov-09 14:32
aaffbbww20-Nov-09 14:32 
GeneralRe: Help With Code Pin
Luc Pattyn20-Nov-09 14:49
sitebuilderLuc Pattyn20-Nov-09 14:49 
AnswerRe: Help With (conversions?) Pin
_Maxxx_22-Nov-09 13:21
professional_Maxxx_22-Nov-09 13:21 
AnswerRe: Help With (conversions?) Pin
dojohansen23-Nov-09 10:26
dojohansen23-Nov-09 10:26 
This will give you a starting point. But handling key-by-key input isn't totally straightforward to do properly. Users will expect normal console functionality to work, including arrow keys, backspace, selecting some text using the mouse and then typing or hitting backspace, cutting and pasting and so on.

This uses ReadKey and intercepts the console, meaning the character is not written. However, other side effects such as changing the cursor position still apply, so if the user presses backspace for example the cursor moves but the character is not removed.

I can't be bothered to try and work out all the specifics for you, but maybe you'd be better off not intercepting and instead writing a backspace and then the double-S char after a 'b' has been input.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(
            "This strange program won't let you type the letter 'b', systematically replacing it with 'ß' instead, "
            + "even though German has the letter 'b' also. Type away, and type 'exit' to quit. Do it now; this "
            + "really is pretty useless.\r\n\r\n");

        string s;
        while ((s = prompt("Input>")).ToLower() != "exit")
        {
            Console.WriteLine("Fantastic, you wrote: {0}\r\n", s);
            Console.WriteLine();
        }
    }

    
    static string prompt(string lead, params object[] args)
    {
        if (args.Length > 0)
            lead = string.Format(lead, args);

        Console.Write(lead);

        var input = new StringBuilder();
        
        while (true)
        {
            var key = Console.ReadKey();
            char c = key.KeyChar.ToString().ToLower()[0];

            if (c == '\r')
                break;

            switch (c)
            {
                case 'b':
                    c = 'ß';
                    break;

                default:
                    c = key.KeyChar;
                    break;
            }

            input.Append(c);
            Console.Write(c);
        }
        Console.WriteLine();
        return input.ToString();
    }
}

QuestionFiles between one or several computers? Via a netowor.? Pin
ahlm20-Nov-09 11:51
ahlm20-Nov-09 11:51 
AnswerRe: Files between one or several computers? Via a netowor.? Pin
mehrdad33321-Nov-09 0:22
mehrdad33321-Nov-09 0:22 
GeneralRe: Files between one or several computers? Via a netowor.? Pin
ahlm21-Nov-09 1:00
ahlm21-Nov-09 1:00 
GeneralMessage Closed Pin
21-Nov-09 1:33
stancrm21-Nov-09 1:33 
GeneralRe: Files between one or several computers? Via a netowor.? Pin
ahlm21-Nov-09 3:12
ahlm21-Nov-09 3:12 
GeneralRe: Files between one or several computers? Via a netowor.? Pin
mehrdad33321-Nov-09 8:09
mehrdad33321-Nov-09 8:09 
GeneralRe: Files between one or several computers? Via a netowor.? Pin
dojohansen23-Nov-09 10:33
dojohansen23-Nov-09 10:33 
Questioncan anyone help plz Pin
Jassim Rahma20-Nov-09 11:32
Jassim Rahma20-Nov-09 11:32 
AnswerRe: can anyone help plz Pin
Not Active20-Nov-09 13:28
mentorNot Active20-Nov-09 13:28 
GeneralRe: can anyone help plz Pin
dojohansen23-Nov-09 10:35
dojohansen23-Nov-09 10:35 
GeneralRe: can anyone help plz Pin
Not Active23-Nov-09 12:10
mentorNot Active23-Nov-09 12:10 
GeneralRe: can anyone help plz Pin
dojohansen23-Nov-09 23:27
dojohansen23-Nov-09 23:27 
Questionload combobox values into datagrid combobox Pin
Ronni Marker20-Nov-09 10:48
Ronni Marker20-Nov-09 10:48 
AnswerRe: load combobox values into datagrid combobox Pin
Ronni Marker20-Nov-09 11:09
Ronni Marker20-Nov-09 11:09 
Questioncodeproject template empty Pin
Rassler4820-Nov-09 6:53
Rassler4820-Nov-09 6:53 
AnswerRe: codeproject template empty Pin
Richard MacCutchan20-Nov-09 7:16
mveRichard MacCutchan20-Nov-09 7:16 
GeneralRe: codeproject template empty Pin
Rassler4820-Nov-09 20:49
Rassler4820-Nov-09 20:49 

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.