PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, June 28, 2022

[FIXED] How create 2 arrays from a multiline textbox for each row in C#? Then I need to plot in a graph those arrays

 June 28, 2022     arrays, c#, graph, textbox     No comments   

Issue

I have this multiline textbox:

14:33:29, 831

14:33:30, 834

14:35:1, 830

14:35:2, 833

I need to create 2 arrays: first to contain data from left (14:33:29,14:33:30,14:35:1,14:35:2) and the second contain data from the right (831,834,830,833). My textbox data are splitted by ",\t". Data from left is DateTime type, and from right is integer. Then I want to make a line graph in C# with those 2 arrays. Can anyone help me, please?

I used this but just the first parameter is displayed.

string[]str = textBox3.Text.Split(',');

        foreach (string row in str)
        {
           
            textBox2.Text = str[0];
        }

Solution

try this, it was tested in visual studio:

var s =
@"14:33:29, 831

  14:33:30, 834

  14:35:1, 830

  14:35:2, 833";
  
var strArr = s.Replace(" ", "").Replace("\n", ";")
.Split(";",StringSplitOptions.RemoveEmptyEntries).Where(a => a.Length>3).ToArray();

    var len=strArr.Length;
    var arr1= new string[len] ;
    var arr2 = new string[len];

    for (var i = 0; i < len; i++)
    {
        var arr = strArr[i].Trim().Split(",");
        if (arr.Length == 2)
        {
            arr1[i] = arr[0];
            arr2[i] = arr[1];
        }
    }

result

arr1= {"14:33:29","14:33:30","14:35:1","14:35:2"};
arr2 ={"831","834","830","833"};


Answered By - Serge
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing