In this example, when 'button3' is pressed the application will read what has been added to 'textBox1' and print it the console each time it loops through.
private void button3_Click(object sender, EventArgs e)
{
for (int i = 1; i <=10; ++i)
{
System.Console.WriteLine (textBox1.Text);
}
}
Showing posts with label Text. Show all posts
Showing posts with label Text. Show all posts
Sunday, 27 September 2009
Trim spaces from the start and end of string using C#
In this example I have a text box on my windows form to collect the user input and a label to display the outcome once a button is pressed. The code is as follows to trim spaces from the beginning and end of a user input.
private void button3_Click(object sender, EventArgs e)
{
string userinput;
char [] trimchars = {' '};
userinput = textBox1.Text.Trim(trimchars);
lable1.Text = userinput;
}
private void button3_Click(object sender, EventArgs e)
{
string userinput;
char [] trimchars = {' '};
userinput = textBox1.Text.Trim(trimchars);
lable1.Text = userinput;
}
Collect user input from form and change it to upper or lower case in C#
In this example I have a text box on my windows form to collect the user input and a label to display the outcome once a button is pressed. The code is as follows to change the input to upper and lower case.
private void button3_Click(object sender, EventArgs e)
{
label1.Text = textBox.Text.ToUpper();
}
or
{
label1.Text = textBox.Text.ToLower();
}
private void button3_Click(object sender, EventArgs e)
{
label1.Text = textBox.Text.ToUpper();
}
or
{
label1.Text = textBox.Text.ToLower();
}
Check if folder exists and return a message in C#
The form I have used for this example contains one label and one button. The code checks the location you specify and then prints a message in the label to tell you if the directory exists.
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
string foldername;
string path;
string combinedpath;
{
foldername = "testfolder";
path = @"C:\blogexample";
combinedpath = path + @"\" + foldername;
if
(Directory.Exists(combinedpath))
label1.Text = "Directory exists";
else
label1.Text = "Directory doesn't exist";
}
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
string foldername;
string path;
string combinedpath;
{
foldername = "testfolder";
path = @"C:\blogexample";
combinedpath = path + @"\" + foldername;
if
(Directory.Exists(combinedpath))
label1.Text = "Directory exists";
else
label1.Text = "Directory doesn't exist";
}
How do you add a value from a webform to a variable in C#?
In Visual Studio 2005 :
Create a webform with a text field and change it's name to 'txtID'
Create another text field to show the result of the variable and change its name to 'txtResult'
Add a button and then add this code to it's click event.
String info = txtID.Text;
txtResult.Text = info;
When the button is clicked it will take the text that is in the field and add it to the variable called 'info. It will then display the value of the variable in the txtResult field.
Create a webform with a text field and change it's name to 'txtID'
Create another text field to show the result of the variable and change its name to 'txtResult'
Add a button and then add this code to it's click event.
String info = txtID.Text;
txtResult.Text = info;
When the button is clicked it will take the text that is in the field and add it to the variable called 'info. It will then display the value of the variable in the txtResult field.
How to merge multiple .csv files into one .txt file using command line
Create a folder on your c: drive called 'All csv files' and place all of your .csv files inside.
Open notepad and add the text below
cd C:\All csv files
copy *.csv Merged.txt
Save the text file and changed its extension to .bat 'merge.bat'.
Double click the file and you will see that a txt file is created in the C:\All csv files folder called 'Merged.txt' with all your consolidated information inside !.
Open notepad and add the text below
cd C:\All csv files
copy *.csv Merged.txt
Save the text file and changed its extension to .bat 'merge.bat'.
Double click the file and you will see that a txt file is created in the C:\All csv files folder called 'Merged.txt' with all your consolidated information inside !.
Subscribe to:
Posts (Atom)