Click here to Skip to main content
16,017,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file in the following format
name : designation : salary :

I would like to extract the info of by taking name as input.

I want to convert the text file to xml file and then use it in form.

Can any one suggest me the procedure in C#.net
Posted
Updated 5-Aug-12 8:06am
v4
Comments
[no name] 5-Aug-12 9:46am    
Your question title and your question have nothing to do with each other. I suppose that String.Split() does not work for you?
Bhargavi Rangam 5-Aug-12 10:02am    
then what works for this problem ?

IF you have a text file you could simply use ReadAllLines[^]

You could make a class that had the variables: name, designation and salary as properties.

Then a Foreach method and split the incoming string by ths char ":".

Stor the items in a new instance of the class you made, and add this to a List(of yourclass).
 
Share this answer
 
Comments
Bhargavi Rangam 5-Aug-12 9:51am    
could u please post the sample code
Assuming your textfile could have several of these entries and looks like:
name : TestEntry designation : Target1 salary : 2345

You could write this code:
C#
private void Form1_Load(object sender, EventArgs e)
{
    string[] lines = File.ReadAllLines(@"C:\Temp\Test.txt");
    foreach( string str in lines )
    {
        string[] parts = str.Split(':');
        if( parts.Length == 4 )
        {
            string name = parts[1].Substring(0, parts[0].IndexOf(' ') + 1).Remove(0,1);
            parts[2] = parts[2].Remove(0, 1);
            string designation = parts[2].Substring(0, parts[2].IndexOf(' ') + 1);
            string salary = parts[3].Remove(0, 1);
            MessageBox.Show("Name: " + name + " Designation: " + designation + " Salary: " + salary);
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900