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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.