Luv L

Luv L

  • 1.3k
  • 141
  • 7.1k

Count lines and numbers in textbox input string values

Nov 2 2024 7:23 AM

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<char>();
           
            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