Professional Documents
Culture Documents
Sa se
gaseasca de cate ori se gaseste acel character in sirul respectiv si sa se afiseze intr-un textbox la
apasarea unui buton. Trebuie sa se tina cont de litera mare si litera mica si sa se afiseze separate
cate is mari si cate is mici.
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
namespace WindowsFormsApplication22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txt1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsLetter(e.KeyChar) && !Char.IsControl(e.KeyChar))
e.Handled = true;
}
private void txt2_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsLetter(e.KeyChar) && !Char.IsControl(e.KeyChar))
e.Handled = true;
}
private void button1_Click(object sender, EventArgs e)
{
int c = 0;
int d = 0;
int t = 0;
char a = Char.Parse(txt2.Text);
string sir = txt1.Text;
if (Char.IsUpper(a))
{
for (int i = 0; i < txt1.TextLength; i++)
{
if (a == sir[i])
{
d++;
txt4mare.Text = d.ToString();
}
}
a = Char.ToLower(a);
for (int j = 0; j < txt1.TextLength; j++)
if (Char.IsLower(a))
{ if (a == sir[j])
{
t++;
txt5mica.Text = t.ToString();
}
}
}
c = d + t;
txt3.Text = c.ToString();
}
else
{
{
}
a = Char.ToUpper(a);
for (int j = 0; j < txt1.TextLength; j++)
{
if (Char.IsUpper(a))
{
if (a == sir[j])
{
t++;
txt4mare.Text = t.ToString();
}
}
}
c = d + t;
txt3.Text = c.ToString();
}
P2. Afiseaza in eticheta numarul de cifre litere si semne de punctuatie dintr-un sir introdus de la
tastatura intr-un textbox.
using System;
using
using
using
using
using
using
using
using
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
namespace WindowsFormsApplication23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txt1_TextChanged(object sender, EventArgs e)
{
}
private void txt1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsLetter(e.KeyChar) && !Char.IsControl(e.KeyChar)&&!Char.IsDigit(e.KeyChar)&&!
Char.IsPunctuation(e.KeyChar))
e.Handled = true;
}
private void button1_Click(object sender, EventArgs e)
{
int nr = 0;
int lit = 0;
int pct = 0;
string sir = txt1.Text;
for(int i=0;i<sir.Length;i++)
{ if(Char.IsDigit(sir[i]))
nr++;
if(Char.IsLetter(sir[i]))
lit++;
if(Char.IsPunctuation(sir[i]))
pct++;}
lblcifre.Text=nr.ToString();
lbllitere.Text=lit.ToString();
lblpunct.Text=pct.ToString();
}
P3.Sa se scrie o aplicatie windows ce citeste un sir de caractere. Afisati intr-un listBox numarul de
cifre litere si punctuatii
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
namespace WindowsFormsApplication24
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txt_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsLetter(e.KeyChar) && !Char.IsControl(e.KeyChar) && !Char.IsDigit(e.KeyChar)
&& !Char.IsPunctuation(e.KeyChar))
e.Handled = true;
}
private void button1_Click(object sender, EventArgs e)
{
int nr = 0;
int lit = 0;
int pct = 0;
string sir = txt.Text;
for (int i = 0; i < sir.Length; i++)
{
if (Char.IsDigit(sir[i]))
nr++;
if (Char.IsLetter(sir[i]))
lit++;
if (Char.IsPunctuation(sir[i]))
pct++;
listBox1.Items.Add("numere:"+nr.ToString());
listBox1.Items.Add("litere:" + lit.ToString());
listBox1.Items.Add( "punctuatii:" +pct.ToString());
}
}