Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
is there any way to write a short code that includes the number (1-10) & Letters (A-Z) ..?? i mean without writing all of it in single lines?

** and btw... the code doesn't support Words? .. i mean when i say a word that doesn't typed there.. it can heart it ..
is there any way to do it ?



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Speech;

namespace System.Speech.Recognition
{
    public partial class Form1 : Form
    {
        SpeechRecognizer rec = new SpeechRecognizer();

        public Form1()
        {
            InitializeComponent();
            rec.SpeechRecognized += rec_SpeechRecognized;
        }

        void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            lblLetter.Text = e.Result.Text;
        }

        void Form1_Load(object sender, EventArgs e)
        {
            var c = new Choices();

            // Doens't work must use English words to add to Choices and
            // populate grammar.
            //
            //for (var i = 0; i <= 100; i++)
            //  c.Add(i.ToString());

            c.Add("one");
            c.Add("two");
            c.Add("three");
            c.Add("four");
            c.Add("hi");
            c.Add("hello");
            c.Add("I");
            c.Add("A");
            c.Add("B");
            c.Add("C");
            c.Add("D");
            c.Add("amer");
            // etc...

            var gb = new GrammarBuilder(c);
            var g = new Grammar(gb);
            rec.LoadGrammar(g);
            rec.Enabled = true;
        }

        private void lblLetter_Click(object sender, EventArgs e)
        {

        }

    }
}
Posted

What's wrong with:
for (char letter = 'A'; letter <= 'Z'; ++letter)
    c.Add(letter.ToString());
 
Share this answer
 
Comments
AspDotNetDev 26-Aug-10 15:49pm    
Reason for my vote of 5
Nice, I didn't know you could just do a for loop over the chars directly.
Katkot 26-Aug-10 16:13pm    
Thanks :)
This should get you started:
C#
string letterA = ((char)97).ToString();
string letterZ = ((char)(97 + 25)).ToString();
MessageBox.Show(letterA + "-" + letterZ);
MessageBox.Show(1.ToString() + "-" + 10.ToString());
 
Share this answer
 
Comments
Katkot 26-Aug-10 13:22pm    
it includes B.. C .. D .. E ... to z ?
the same on numbers ?
AspDotNetDev 26-Aug-10 13:25pm    
Think for yourself for a second. Read the code to see what it does. Heck, you might even try running it. From there, try expanding it for your needs. This code is not rocket science... give it a try.
Katkot 26-Aug-10 13:26pm    
Thanks, I did.
That's not What I need :)
AspDotNetDev 26-Aug-10 13:35pm    
You may want to consider editing your question to more clearly convey your needs. The second paragraph in your question doesn't make a whole lot of sense.
Katkot 26-Aug-10 13:54pm    
:) Thank you for replaying .. But my question is ..

Is there any code that includes all the letter from A to Z ..
Instead of typing
c.Add("A");
c.Add("B");
c.Add("C");
c.Add("D");

etc to Z ..

?


Just for making the code more short :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900