TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
albert albert
NA
524
0
How to get the names under the header
Aug 29 2014 6:12 AM
Hi everybody,
I have this:
[code]
Hi everybody,
I have this:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class Program
{
static void Main(string[] args)
{
//Consider making this configurable
const string sourceFile = "testSolar.txt";
const string pattern = "http://10.123.9.66:80";
//var FirstSeparatorLastNameExact = new[] { "nosyn_name_last_exact:(qxq" };
//var SecondSeparatorLastNameExact = new[] { "qxq)" };
string[] FirstSeparator = new string[] { "nosyn_name_last_exact:(qxq" };
string[] SecondSeparator = new string[] { "qxq)" };
string[] FirstSeperatorFirstName = new string[] {"nosyn_name_first_exact:(qxq"};
string[] secondSeperatorFirstName = new string[]{"qxq)"};
Regex re = new Regex("^(http|https)://");
HttpWebResponse response;
// var webClient = new WebClient();
var times = new Dictionary<string, TimeSpan>();
var stopwatch = new System.Diagnostics.Stopwatch();
//Add header so if headers are tracked, it will show it is your application rather than something ambiguous
//webClient.Headers.Add(HttpRequestHeader.UserAgent, "Response-Tester-Client");
var urlList = new List<string>();
//Loop through the lines in the file to get the urls
try
{
stopwatch.Start();
using (var reader = new StreamReader(sourceFile))
{
while (!reader.EndOfStream)
{
var urNewList = new List<string>();
var line = reader.ReadLine();
//line = line.Substring(line.IndexOf(pattern));
//line.Split("\t");
var columns = line.Split('\t');
//var result = line.Split(Seperator, StringSplitOptions.RemoveEmptyEntries)[1].Split(')')[0];
if (columns[2] == "R")
{
var url = columns[4] + "?" + columns[5];
urlList.Add(url);
Thread.Sleep(250);
}
//if (line.Contains(result))
//{
//MatchCollection matches = Regex.Matches(line, lastName);
//foreach (string lines in File.ReadLines(sourceFile))
//{
//var LastNameSearch = line.Split(FirstSeparatorLastNameExact, StringSplitOptions.RemoveEmptyEntries)[1];
//var resultLastNameSearch = LastNameSearch.Split(FirstSeparatorLastNameExact, StringSplitOptions.RemoveEmptyEntries)[0];
var temp = line.Split(FirstSeparator, StringSplitOptions.RemoveEmptyEntries)[1];
var result2 = temp.Split(SecondSeparator, StringSplitOptions.RemoveEmptyEntries)[0];
Console.WriteLine(result2);
//var split = line.Split(FirstSeperatorFirstName, StringSplitOptions.RemoveEmptyEntries);
//if (split.Length > 1)
//{
// Console.WriteLine(split[1].Split(')')[0]);
//}
//string[] result = line.Split(FirstSeperatorFirstName, StringSplitOptions.RemoveEmptyEntries);
//if (line.Contains("nosyn_name_first_exact:(qxq"))
//{
// if (result.Length > 2)
// {
// string[] inner = result[1].Split(')');
// if (inner.Length > 1)
// {
// Console.WriteLine(inner[0]);
// Console.WriteLine(result);
// }
// }
//}
//var split = line.Split(FirstSeperatorFirstName, StringSplitOptions.RemoveEmptyEntries);
//if (split.Length > 1)
//{
// Console.WriteLine(split[1].Split(')')[0]);
// // Console.WriteLine(split);
//}
}
}
}
catch (Exception e)
{
Console.WriteLine("An error occured while attempting to access the source file at {0}", sourceFile);
}
finally
{
//Stop, record and reset the stopwatch
stopwatch.Stop();
times.Add("FileReadTime", stopwatch.Elapsed);
stopwatch.Reset();
}
//Try to connect to each url
var counter = 1;
foreach (var url in urlList)
{
try
{
stopwatch.Start();
using (WebClient webClient = new WebClient())
{
webClient.Headers.Add(HttpRequestHeader.UserAgent, "Response-Tester-Client");
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
//webClient.Dispose();
}
}
catch (Exception e)
{
Console.WriteLine("An error occured while attempting to connect to {0}", url);
}
finally
{
stopwatch.Stop();
//We use the counter for a friendlier url as the current ones are unwieldly
times.Add("Url " + counter, stopwatch.Elapsed);
counter++;
stopwatch.Reset();
}
}
//Release the resources for the WebClient
//webClient.Dispose();
//Write the response times
Console.WriteLine("Url " + "\t\t\t\tLast Name");
foreach (var key in times.Keys)
{
Console.WriteLine("{0}: {1}", key, times[key].TotalSeconds);
}
Console.ReadKey();
}
}
}
And here is the screenshot from the ouput:
![enter image description here][1]
[1]: http://i.stack.imgur.com/PCqry.png
But in the output you see a lastname but the names are at the top of the output, and I want them under the header: Last name. Will be nice to get some hints.
Thank you
[/code]
So I have a header last name, but I want to have the names under that header. this is the code for the names:
var temp = line.Split(FirstSeparator, StringSplitOptions.RemoveEmptyEntries)[1];
var result2 = temp.Split(SecondSeparator, StringSplitOptions.RemoveEmptyEntries)[0];
Console.WriteLine(result2);
Thank you
Reply
Answers (
0
)
find and hightlight text in texbox
Registry is not working