hi,
iam using below code for my below task
| task-1 | task-2 | |
| textbox1 | textbox1 | |
| 1.2.3. | [1.2.3. | |
| 4.5.6. | 4.5.6.]10. | |
| 7.8.9. | 7.8.9. | |
| 10.11.12. | 10.11.12. | |
| [1.2. | ||
| 3.4.]2. | ||
| 1.2.3.4 | ||
| 4 = lines - 12=no | 27 = lines - 78=no |
private void RsButton7_Click_1(object sender, EventArgs e)
{
int countLines = 0;
int countNumbers = 0;
var stack = new Stack();
int num;
foreach (string line in txtDraft.Lines)
{
if (line.Trim() == "") continue; // ignore blank lines
string[] items = line.Split('.');
foreach (string item in items)
{
if (int.TryParse(item, out num)) countNumbers++;
}
countLines++;
rsLabel1.Text = countLines + " = lines" + " - " + countNumbers + " = no".ToString();
}
}
task-1 work well using above code.
but i want also like task-2 like above given task-2 input.
please anybody share the update code.
Thanks in Advance.
Varta
Muhammad Imran AnsariPosted Nov 6, 2024, 7:39 AM
Hi Luv,
Here is the revised code which you can use.
Thank you.
Luv LPosted Nov 5, 2024, 5:43 AM
@Muhammad Imran Ansari,
Thanks for code.in this code count numbers work ok.but count lines not work correct.if we use bracket with then its not caluclated lines.
Textbox1
1.2.3.
4.5.6.
[1.2.
3.4]5.
1.2.3.4.
5 = lines
30 = numbers
Here 5 lines is wrong.
it should be after close bracket number is 5
so 5 x 2 lines = 10. + remain without using bracket
lines 3
so taltal lines should be 13 is correct answer.
so look in to this and share revised pls.
Muhammad Imran AnsariPosted Nov 4, 2024, 11:12 AM
Hi Luv L,
You can try the below code for your problem statement.
Thank you.!
Luv LPosted Nov 4, 2024, 7:21 AM
Kindly anybody solve this.
Luv LPosted Nov 2, 2024, 5:35 PM
Dear @Local Coders,
Thanks for your reply.i have already done result same as above code for task-1 like above mentioned.
if i want to start "[" open and "]"close bracket with multiply tnumbers like 10 (multiply number may be any number) used like above task2.then result will come as per above code.if i want to change the input in textbox using bracket with timing what is the impliment of code.
i hope ypu understand my logic.
Thanks.
Local CodersPosted Nov 2, 2024, 4:41 PM
private void textBox1_TextChanged(object sender, EventArgs e)
{
// Count lines
int lineCount = textBox1.Lines.Length;
labelLineCount.Text = "Lines: " + lineCount;
// Count numbers
int numberCount = CountNumbers(textBox1.Text);
labelNumberCount.Text = "Numbers: " + numberCount;
}
private int CountNumbers(string text)
{
int numberCount = 0;
string[] words = text.Split(new char[] { ' ', '\n', '\r', '\t' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in words)
{
if (int.TryParse(word, out _)) // Checks if the word is a number
{
numberCount++;
}
}
return numberCount;
}