how to create a character array which will accept 8 characters from the user and than convert that array into string variable and if the user gives the more than 8 characters the program will throw an error. it's very difficult????

vinnitro commented: you are right he should show something b4 asking here +0

Recommended Answers

All 5 Replies

What have you done so far? We'll help with your homework, but not do it for you.

commented: you are right he should show something b4 asking here +2
char[] ar = new char[8];

                Console.WriteLine("Enter The FileName(MAX 10 Alphabets");

               for (int i = 0; i<8; i++)
                    {
                        ar[i] = Convert.ToChar(Console.ReadLine());  
                    }
                    for (int j = 0; j<8; j++)
                    {
                     //how to convert array into string with help of loop.   
                    }
                    //missing the error statement
string output="";
for (int j = 0; j<8; j++)
{
//how to convert array into string with help of loop.
output += ar[j];
}
Console.WriteLine(output);

you can convert the character array into string like that...

On a second note, why are u taking a character array?? you can directly use a string variable. and then check if the value is more than 8 characters... and whatever u want

using System;
class Satvinder
{
    static void Main()
        {
            string name = Console.ReadLine();
            char[] naam;

            if(name.Length>8 || name.Length<=0)
            {
                Console.WriteLine("Please re-enter file name");
            }

            else 
            {
                naam = name.ToCharArray();

                for (int i = 0; i <8; i++)
                {
                    Console.WriteLine(naam[i]);
                }
            }
        }
}   

if you got the answer you have to mark it solved
Dont give any code plz first he have to show what he have done so far

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.