Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I have no experience converting text not in csv or other tabluar structure.
The only way I get data is in a text file like below.
I have tried many ways with this:

C#
    <script language="c#" runat="server">
  public void Page_Load(object sender, EventArgs e)
{
    string FILENAME = Server.MapPath("users_db_match.txt");
    StreamReader objStreamReader = default(StreamReader);
	objStrea<code><code><code></code></code></code>mReader = File.OpenText(FILENAME);
    string contents = objStreamReader.ReadToEnd();
    string strData = contents ;
    char[] separator = new char[] { '\\' };
    string[] strSplitArr = strData.Split(separator);
    foreach (string arrStr in strSplitArr)
    {
     Response.Write(arrStr + " ");
    }


But I am having no luck. Here is an example of the text structure:

 # Senseless text
    # 
    #
    /from what folder
    add comment="" customer=Multi disabled=no first-name=Joseph last-           name=Won \
    location="6333 Co. Rd 53 Where, AL 35045" name=joeandstacy password=\
    took1 shared-users=3
add comment="" customer=Multi disabled=no email=carl_l@yahoo.com \
    first-name=Carl last-name=Pop location=\
    "6359 Co. Rd 53 Townin, AL 35045" name=carl_l password=\
    20579 phone=205-755-5555 shared-users=3



The columns are immediately before the = and the data is immediately after. It also has \ breaking the text into new lines in the middle of a record.
Customer disabled email first-name
Multi no Carl
Multi no carl_l@yahoo.com Joseph


Am I even on the write track with the string functions? Once I get it converted to a csv or other format that excel can read I'll save the new structure as a file again. I know this is very complicated but would appreciate any help. Thanks.
Posted
Updated 10-Jan-11 23:44pm
v4
Comments
Dalek Dave 11-Jan-11 6:13am    
Edited for Grammar, Syntax and Readability.

I would recommend writing your own simple scanner for this. Using the string functions like you are doing now won't do because they are to generic for this. You process it character by character following these steps:

You first skip whitespace: space, cr, lf, \, eof

You start reading the column name (until you encounter the "=" sign): a-z,-

You read the value, this can be:
1. between first en second quote: "... ..."
2. Until you encounter a white space: ...

Repeat those steps until you are done. Write simple methods for dealing with each single step and you'll be done in no-time.

Good luck!
 
Share this answer
 
v4
Don't mean to sound totally in the dark but what type of "simple scanner" setup would you suggest? I did a literal search through google for asp.net C# code scanner and nothing caught my attention. At least now I know the string function was going down the wrong ally. I appreciate all the help.
 
Share this answer
 
v2

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