|
Hi,
I want to go to particular line number in a text file directly. How we can do using c#???
Just When i send a line numnber in a function, it directly goes to that line.
please help me........
Thanks in advance
G. Satish
|
|
|
|
|
How do you mean, 'go to the line' ? If you use File.ReadAllLines, you can get an array and use an array index to access the line you want.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I dont want to read a line by lline from a text file.
My requirement is, the cursor directly goes to particular linenumber whatever i passed in function.
Ex: In Notepad, if we use ctrl+G - then it will takes directly to particular line.
In the same way, without reading data from text file line by line, i need to go the cursor directly...
|
|
|
|
|
OK - so you have a textbox and you want to move the cursor to a line ? You have to count the lines in the text file because you can only position the cursor by character index. And you need to count when the text has wrapped, too.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Thank U, The link which u have given is helped a lot, thank u....
|
|
|
|
|
Funny, that article shows how to do what you specifically said that you don't want to do...
Well, that's the only way to do it anyhow. It's impossible to find out where a line in a text file is without reading the previous lines.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I Have 8 usercontrol and 1 form . I am useing the enumeration and dictornay for the selection of the usercontrol.
Form the second usercontrol their are 2 radiobutton . from the second usercontrol next user control selection will be done according to the selection of the radiobutton which will go to different usercontrol according to the radiobutton selection.
please help me
MURALEEKRISHNAN
|
|
|
|
|
what are you trying to ask?
if you just want to get the selected value from the user control then you can do it in multiple ways:
1. declare user control on the master page, declare radiobuttonlist and get the radiobuttonlist from the user control using findcontrol and check the selectedindex in the list
2. add event handler to the usercontrol and get the value in the selectedindexchange event
-----
|
|
|
|
|
Hello experts,
I having a data table with 10,000 records and I have to traverse to each record to find some specific data. For that I have to loop through 10,000 records. So I decided to copy the match column say [Item Name] into the Array list, So I can use arraylist.contains method which will automatically tells record found or not.
And I have to match 5 records every time into the 10,000 records. So my loop is running 50,000 times.
How can copy a single column value of data table into the Array list....?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
why you need array for to do this?
you should use DataTable.Select(expression as string)
one simple example is here:
DataTable table = DataSet1.Tables["Orders"];<br />
string expression;<br />
expression = "Date > '1/1/00'";<br />
DataRow[] foundRows;<br />
<br />
foundRows = table.Select(expression);<br />
<br />
for(int i = 0; i < foundRows.Length; i ++)<br />
{<br />
Console.WriteLine(foundRows[i][0]);<br />
you can change the above code as per your requirement, or look in MSDN for DataTable.Select for more options
-----
|
|
|
|
|
First of all thanks for your reply.
Actually I have to check 5 or more items each time to the 10,000 records of the datatable.
Your solution is good but it will work only for one time
I have to change
expression = "ItemName = 'mobile'";
5 times. Like
expression = "ItemName = 'mobile'";
expression = "ItemName = 'tv'";
expression = "ItemName = 'radio'";
expression = "ItemName = 'computer'";
SO how I do that...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well you should be able to add multiple expressions using and/or e.g.
expression = "ItemName = 'mobile' or ItemName = 'tv' or ItemName = 'radio' or ItemName = 'computer'";
you can try in also like "ItemName in('mobile','tv', 'radio', 'computer')"
and if you have any primary key in the table then use DataTable.Rows.Find instead of .Select()..
-----
|
|
|
|
|
Dear SABhatti,
Actually I want to know weather or not any item is mismatch. Suppose I have 5 items and 2 items are missing then the functions should say their are 2 items are missing.
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well you can check the number of rows (foundRows.Length) found and show the message accordingly
-----
|
|
|
|
|
Sir,
foundRows.Length returns what...?
0 means...?
1 means...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
0 means: did not find any row for your criteria
1 means: found 1 row for your criteria
-----
|
|
|
|
|
Ok. Then it is difficult to find which item is missing...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well I am sorry, but are you a programmer?
if you want that then you can find all rows one by one and see what you are missing. Or you can compare the results again for your criteria and see what you are missing.
-----
|
|
|
|
|
YES YES YES !!!!
I am a programmer , and facing problems so ask this question.
Why are you asking that...? Any prob...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well, sorry if you are offended. but normally people ask for guidance/hints in the forums and you can't even think/do this simple thing after you have all the code to find the results... all code was there and now you just had to think a very little to do your task but you posted the next question without thinking ... if you really want to learn then please spend some time in making your logic on paper before start coding..
-----
|
|
|
|
|
Yes, sir you are right.
Actually what is happening, I am having more than 23,000 items and I don't want to traverse. I search a lot but no good solution is found. And if I am having 10 records in a new order then I have to traverse through the 23thousand records so I ask a solution.
The solution you provide is good but I unable to understand how I can found the unmatched items...?
At the end of all.... I am very very sorry if I hurt you any way.
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
well without going in detail here is the quick fix for you:
<br />
<br />
bool testMatched, test1Matched, test2Matched, test4Matched;<br />
testMatched = false;<br />
test1Matched = false;<br />
test2Matched = false;<br />
test4Matched = false;<br />
<br />
foundRows = datatable.Select("itemName='test' or itemName='test1' or itemName='test2' or itemName='test4'");<br />
<br />
if(foundRows.Length > 0)<br />
{<br />
for(int i=0; i<foundRows.Length; i++)<br />
{<br />
switch(foundRows[i]["itemName"])<br />
{<br />
case "test":<br />
testMatched = true;<br />
break;<br />
case "test1":<br />
test1Matched = true;<br />
break;<br />
case "test2":<br />
test2Matched = true;<br />
break;<br />
case "test4":<br />
test4Matched = true;<br />
break;<br />
}<br />
}<br />
}<br />
<br />
if(!testMatched)<br />
Response.Write("Test did not found");<br />
hope this will help you
-----
|
|
|
|
|
Thanks for your reply sir...
I also create a logic can you check it for me?
//Filling the datatable
dataTableItems....
///Create the generic object
List<string> listNoOfItems = new List<string>();
//Adding the search item into the list
listNoOfItems.Add("Item1");
listNoOfItems.Add("Item2");
for (int listIndex = 0; listIndex <= listNoOfItems.Count - 1; listIndex++)
{
DataRow[] foundRows;
//Finding the rows....
foundRows = dataTableItems.Select("ItemName = '" + listNoOfItems[listIndex] + "'");
if (foundRows.Length <= 0)
{
MessageBox.Show("Not found " + listNoOfItems[listIndex]);
}
else
{
MessageBox.Show("Found " + foundRows[0]["ItemName"].ToString());
}
}
Will this code is OK...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
Why not create separate DataRow arrays for each expression if you want to segregate them, or use OR in your select string if you want to group them all together?
For example (using expresion segregation):
DataTable dt = ...(your data table definition)
DataRow[] drMobile = dt.Select("ItemName = 'mobile'");
DataRow[] drTV = dt.Select("ItemName = 'tv'");
DataRow[] drRadio = dt.Select("ItemName = 'radio'");
DataRow[] drComputer = dt.Select("ItemName = 'computer'");
or (grouping them all together):
DataTable dt = ...(your data table definition)
DataRow[] drows = dt.Select("ItemName = 'mobile' OR ItemName = 'tv' OR ItemName = 'radio' OR ItemName = 'computer'");
By the way, I don't recommend using ArrayList... instead, use Generics, for example, instead of using:
ArrayList al = new ArrayList();
string v1 = "some text";
string v2 = "some more text";
string v3 = "even more text";
// you get the point...
al.Add(v1);
al.Add(v2);
al.Add(v3);
// etc.
and then casting the content back to a string variable:
string v1Str = (string)al[0];
...
Use Generics:
List<string> al = new List<string>();
string v1 = "some text";
string v2 = "some more text";
string v3 = "even more text";
al.Add(v1);
al.Add(v2);
al.Add(v3);
// etc.
now, you don't have to cast the values back to a string when you retrieve them:
string v1Str = al[0];
string v2Str = al[1];
...
Depending on what you are storing in the ArrayList, the cast operation can be very costly in terms of performance.
Microsoft doesn't recommend using the ArrayList in .NET 2.0 and higher.
-- modified at 22:03 Sunday 18th November, 2007
|
|
|
|