Automator
BAN USERI am a candidate for MS in computer science and working as SDET . I like developing test automation frameworks and web applications.
Do you mean , how to split a string using space as the separator ?
Does this work for you?
public static void SplitStringUsingSpace(string str)
{
var pattern = @"\s+"; //Find one or more space
var afterSplit = Regex.Split(str, pattern);
foreach (var item in afterSplit)
{
Console.WriteLine(item);
}
}
string str = @"Split Me Using Regex("")";
SplitStringUsingSpace(str);
Output:
Split
Me
Using
Regex("")
This solution is going to work if the marks are out of 100.
int count = 0;
int total = 0;
var allLinesInFile = File.ReadAllLines(@"File.txt");
for (int i = 0; i < allLinesInFile.Length; i++)
{
var currentLine = allLinesInFile[i].Trim(); // remove the extra space at the end of the string
if (currentLine.Contains("Data Structure"))
{
count++;
int length = currentLine.Length;
string substring = currentLine.Substring(length - 2); //gets the last two characters
int value = 0;
bool tryToGetMarks = int.TryParse(substring, out value);
if (tryToGetMarks)
{
Console.WriteLine("Marks in data structures are " + value);
total += value;
}
}
}
Console.WriteLine("Count is " + count);
Console.WriteLine("Total is: " + total);
Console.WriteLine("Average is: " + total / count);
Sorry about the above comment . New to career cup.
Just finished testing that function with the inputs mentioned above and I got the answer. For clarity I have written it in terms of Char array.
- Automator August 02, 2014