如何找出文字 [英] how to find out the text
本文介绍了如何找出文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我也在google中搜索过..但我没有得到.任何人都可以帮助..?
接受文本并查找以下内容-
1.字母中的字母总数.
2.总字数
3.字母"a"的总数
使用一个文本框和一个按钮.
[txtbox] [button]
i searched in google too..but m not getting.any one will help..?
Accept text and find out the following-
1.Total number of letters in the alphabets.
2.Total number of words
3.Total number of letter "a"
using one textbox and button.
[txtbox] [button]
推荐答案
正如我所承诺的,这是#2的解决方案:
Hi,
as I promised, here is solution for #2:
private void button1_Click(object sender, EventArgs e)
{
string message = textBox1.Text;
string[] splittedMessage = message.Split(new char[]{' '},
StringSplitOptions.RemoveEmptyEntries);
//string[] spliitedMessage = message.Split(' ');
int wordCount = 0;
wordCount = spliitedMessage.Length;
MessageBox.Show(wordCount.ToString());
}
#3的解决方案:
solution for #3:
private void button1_Click(object sender, EventArgs e)
{
string message = textBox1.Text;
char[] letters = message.ToCharArray();
int aCount = 0;
foreach (char letter in letters)
{
if (letter == 'a' || letter == 'A')
{
aCount++;
}
}
MessageBox.Show(aCount.ToString());
}
如果这解决了您的问题,请标记为答案并投票5
最好的问候,
爱德华
Please mark as answer and vote 5 if this solved your problem
Best regards,
Eduard
这篇关于如何找出文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文