Hi All,
I want to read text from .txt file in between 2 specific fields like
Account_NUMBER>1298406
I want to get '1298406' as. The file which I am using contains multiple records with different account numbers.
Can some one please help me?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Posted Jun 11, 2012, 10:02 PM EDT
Read the xml content by using XMLDocument and read the values Account_number tag values.
XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString); // suppose your file content
XmlNodeList xnList = xml.SelectNodes("/Customers/Customer");
foreach (XmlNode xn in xnList)
{
string accnumber = xn["Account_NUMBER"].InnerText;
Console.WriteLine("account number: {0}", accnumber);
}
http://support.microsoft.com/kb/307548
You can also try with LINQ to XML also.
var doc = XDocument.Load("yourfile.txt");
var nodes = from d in doc.Desendants("Customer")
select d;
foreach(var node in nodes)
{ // do stuff with node
}
the above code is not tested.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 12, 2012, 4:49 AM EDT
Are you text file contain XML?
if yes please refer
http://www.csharp-examples.net/xml-nodes-by-name/
you can also get it from Regex
string regExp = @"<(.*)Account_NUMBER>(.*)(.*)Account_NUMBER>";//@"(?m)^(\)(.*)$";
string text = File.ReadAllText(@"E:\test11.txt");
string result = Regex.Match(text, regExp).Groups[2].Value;
hope this will help you.Muhammad Masood4 reputationPosted Jun 12, 2012, 9:08 PM EDT
I have Done it by below code
string orderNo = "";") == -1)") + 15); ")) + "'" + "\r\n";
int count = 0;
while (true)
{
if (txtFromFiles.IndexOf("
{
break;
}
else
{
txtFromFiles = txtFromFiles.Substring(txtFromFiles.IndexOf("
orderNo += ",'" + txtFromFiles.Substring(0, txtFromFiles.IndexOf("
}
count++;
It gives me all orders in a sequence the exists in the file.
Again thanx alot brothers.