?
Solved

text file array

Posted on 2012-09-04
19
Medium Priority
?
412 Views
Last Modified: 2012-09-07
hey guys, how do i save this information into an array or class from a text file?

i have saved the text file into a file stream

FIRST_NAME  = Mike
MIDDLE_NAME  = Johnson
LAST_NAME  = Kofman
CUSTOMER_ID =  14112
PRODUCT_DETAILS = MP_A4 Portrait
PRICE_LEFT_DECIMAL_POINT = 1189
PRICE_RIGHT_DECIMAL_POINT =39
DATE_TIME = 19145504122008
STREET =157th St.
DISTRICT = NY
CITY =New York
ZIP = 75443
STATE = NY
COUNTRY = America 
PHONE =  054533526
CELLULAR = 054533526
EMAIL = Kofman_Mike@hotmail.com
ATTEMPT_TO_UPLOAD =0
COVER_MATERIAL = Dark_Cover
COVER_COLOR = Gray
PAGE_COUNT = 40
COPIES = 1
COMMENT = 
FINISHING = 
COLOR_CORRECT = 0
IMAGE_COUNT = 7
CUSTOMER_TITLE = Mr.
CUSTOMER_BIRTHDATE = 00000023111972
USED_PRICING_FORMAT = 1
DECIMAL_SEPARATOR = .
BASIC_PAGES_PRICE = 454.00
ADDITIONAL_PAGES_PRICE = 155.00
ALBUM_BLOCK_PRICE = 564.00
COVER_PRICE = 200.00
COLOR_CORRECTION_PRICE = .00
FINISHING_PRICE = .00
ALBUM_PRICE = 1074.00
CD_PRICE = .00
ORDER_PRICE = 1074.00
TAX_NAME_1 = VAT
TAX_VALUE_1 = 107.40
TAX_NAME_2 = Shipment Tax
TAX_VALUE_2 = 2.99
ORDER_PRICE_INCLUDING_TAXES =1184.39
SHIPMENT_PRICE = 5.00
TOTAL_PRICE = 1189.39
DISCOUNT = .00
PAYED_AMOUNT = .00 

Open in new window

0
Comment
Question by:JCWEBHOST
  • 8
  • 4
  • 3
  • +2
17 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38362626
JC, That's the 3rd question related to the same topic.
0
 
LVL 19

Expert Comment

by:Bardobrave
ID: 38362955
You can convert directly a String to an Array through String.split method.

Just pass it a char delimiter (line feed in this case) and it should work.

More info on the method:
http://msdn.microsoft.com/es-es/library/system.string.split%28v=vs.80%29.aspx
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38363203
Hi
I was about to post a response to the last thread, but then it got deleted, hmmm.

I got this far with the last question titled "text files in asp" before it disappeared ...

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  Sub Page_Load(sender As Object, e As EventArgs)
    
    
    Dim strTemp As String = ""
    Dim FIRST_NAME As String = ""
    Dim MIDDLE_NAME As String = ""
    Dim LAST_NAME As String = ""
    Dim PRODUCT_DETAILS As String = ""
    Dim PRICE_LEFT_DECIMAL_POINT As String = ""
    Dim PRICE_RIGHT_DECIMAL_POINT As String = ""
    Dim DATE_TIME As String = ""
    Dim STREET As String = ""
    Dim DISTRICT As String = ""
    Dim CITY As String = ""
    Dim ZIP As String = ""
    Dim STATE As String = ""
    Dim COUNTRY As String = ""
    Dim PHONE As String = ""
    Dim CELLULAR As String = ""
    Dim EMAIL As String = ""
    Dim COVER_MATERIAL As String = ""
    Dim ATTEMPT_TO_UPLOAD As String = ""
    Dim COVER_COLOR As String = ""
    Dim PAGE_COUNT As String = ""
    Dim COPIES As String = ""
    Dim COMMENT As String = ""
    Dim FINISHING As String = ""
    Dim COLOR_CORRECT As String = ""
    Dim IMAGE_COUNT As String = ""
    Dim CUSTOMER_ID As String = ""
    Dim CUSTOMER_TITLE As String = ""
    Dim CUSTOMER_BIRTHDATE As String = ""
    Dim USED_PRICING_FORMAT As String = ""
    Dim DECIMAL_SEPARATOR As String = ""
    Dim BASIC_PAGES_PRICE As String = ""
    Dim ADDITIONAL_PAGES_PRICE As String = ""
    Dim ALBUM_BLOCK_PRICE As String = ""
    Dim COVER_PRICE As String = ""
    Dim COLOR_CORRECTION_PRICE As String = ""
    Dim FINISHING_PRICE As String = ""
    Dim ALBUM_PRICE As String = ""
    Dim CD_PRICE As String = ""
    Dim ORDER_PRICE As String = ""
    Dim TAX_NAME_1 As String = ""
    Dim TAX_VALUE_1 As String = ""
    Dim TAX_NAME_2 As String = ""
    Dim TAX_VALUE_2 As String = ""
    Dim ORDER_PRICE_INCLUDING_TAXES As String = ""
    Dim SHIPMENT_PRICE As String = ""
    Dim TOTAL_PRICE As String = ""
    Dim DISCOUNT As String = ""
    Dim PAYED_AMOUNT As String = ""

    Dim myVarsArray As String() = {"FIRST_NAME", "MIDDLE_NAME", "LAST_NAME", "PRODUCT_DETAILS", "PRICE_LEFT_DECIMAL_POINT", "PRICE_RIGHT_DECIMAL_POINT", "DATE_TIME", "STREET", "DISTRICT", "CITY", "ZIP", "STATE", "COUNTRY", "PHONE", "CELLULAR", "EMAIL", "COVER_MATERIAL", "ATTEMPT_TO_UPLOAD", "COVER_COLOR", "PAGE_COUNT", "COPIES", "COMMENT", "FINISHING", "COLOR_CORRECT", "IMAGE_COUNT", "CUSTOMER_ID", "CUSTOMER_TITLE", "CUSTOMER_BIRTHDATE", "USED_PRICING_FORMAT", "DECIMAL_SEPARATOR", "BASIC_PAGES_PRICE", "ADDITIONAL_PAGES_PRICE", "ALBUM_BLOCK_PRICE", "COVER_PRICE", "COLOR_CORRECTION_PRICE", "FINISHING_PRICE", "ALBUM_PRICE", "CD_PRICE", "ORDER_PRICE", "TAX_NAME_1", "TAX_VALUE_1", "TAX_NAME_2", "TAX_VALUE_2", "ORDER_PRICE_INCLUDING_TAXES", "SHIPMENT_PRICE", "TOTAL_PRICE", "DISCOUNT", "PAYED_AMOUNT"}
    
    'Open a file for reading
    Dim FILENAME As String = Server.MapPath("~/the-files-folder/TextFile.txt")

    'Get a StreamReader class that can be used to read the file
    Dim objStreamReader As StreamReader
    objStreamReader = File.OpenText(FILENAME)

    'Now, read the entire file into a string
    Dim contents As String = "" 'objStreamReader.ReadToEnd()
    Dim line As String = ""
    While Not objStreamReader.EndOfStream
      line = objStreamReader.ReadLine()
      
      ' sanitise the doublespaces and equals operators
      line = line.Replace("  = ", " = ")
      line = line.Replace(" =  ", " = ")
      line = line.Replace(" =", " = ")
      line = line.Replace("  ", " ")
      
      ' Populate our local variables
      For i = 0 To myVarsArray.Length - 1
        If line.Contains(myVarsArray(i) & " = ") Then
          Select Case myVarsArray(i)
            Case Is = "FIRST_NAME"
              FIRST_NAME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & FIRST_NAME & "<br />"
            Case Is = "MIDDLE_NAME"
              MIDDLE_NAME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & MIDDLE_NAME & "<br />"
            Case Is = "LAST_NAME"
              LAST_NAME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & LAST_NAME & "<br />"
            Case Is = "PRODUCT_DETAILS"
              PRODUCT_DETAILS = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PRODUCT_DETAILS & "<br />"
            Case Is = "PRICE_LEFT_DECIMAL_POINT"
              PRICE_LEFT_DECIMAL_POINT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PRICE_LEFT_DECIMAL_POINT & "<br />"
            Case Is = "PRICE_RIGHT_DECIMAL_POINT"
              PRICE_RIGHT_DECIMAL_POINT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PRICE_RIGHT_DECIMAL_POINT & "<br />"
            Case Is = "DATE_TIME"
              DATE_TIME = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DATE_TIME & "<br />"
            Case Is = "STREET"
              STREET = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & STREET & "<br />"
            Case Is = "DISTRICT"
              DISTRICT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DISTRICT & "<br />"
            Case Is = "CITY"
              CITY = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CITY & "<br />"
            Case Is = "ZIP"
              ZIP = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ZIP & "<br />"
            Case Is = "STATE"
              STATE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & STATE & "<br />"
            Case Is = "COUNTRY"
              COUNTRY = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COUNTRY & "<br />"
            Case Is = "PHONE"
              PHONE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PHONE & "<br />"
            Case Is = "CELLULAR"
              CELLULAR = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CELLULAR & "<br />"
            Case Is = "EMAIL"
              EMAIL = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & EMAIL & "<br />"
            Case Is = "COVER_MATERIAL"
              COVER_MATERIAL = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COVER_MATERIAL & "<br />"
            Case Is = "ATTEMPT_TO_UPLOAD"
              ATTEMPT_TO_UPLOAD = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ATTEMPT_TO_UPLOAD & "<br />"
            Case Is = "COVER_COLOR"
              COVER_COLOR = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COVER_COLOR & "<br />"
            Case Is = "PAGE_COUNT"
              PAGE_COUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PAGE_COUNT & "<br />"
            Case Is = "COPIES"
              COPIES = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COPIES & "<br />"
            Case Is = "COMMENT"
              COMMENT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COMMENT & "<br />"
            Case Is = "FINISHING"
              FINISHING = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & FINISHING & "<br />"
            Case Is = "COLOR_CORRECT"
              COLOR_CORRECT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COLOR_CORRECT & "<br />"
            Case Is = "IMAGE_COUNT"
              IMAGE_COUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & IMAGE_COUNT & "<br />"
            Case Is = "CUSTOMER_ID"
              CUSTOMER_ID = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CUSTOMER_ID & "<br />"
            Case Is = "CUSTOMER_TITLE"
              CUSTOMER_TITLE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CUSTOMER_TITLE & "<br />"
            Case Is = "CUSTOMER_BIRTHDATE"
              CUSTOMER_BIRTHDATE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CUSTOMER_BIRTHDATE & "<br />"
            Case Is = "USED_PRICING_FORMAT"
              USED_PRICING_FORMAT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & USED_PRICING_FORMAT & "<br />"
            Case Is = "DECIMAL_SEPARATOR"
              DECIMAL_SEPARATOR = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DECIMAL_SEPARATOR & "<br />"
            Case Is = "BASIC_PAGES_PRICE"
              BASIC_PAGES_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & BASIC_PAGES_PRICE & "<br />"
            Case Is = "ADDITIONAL_PAGES_PRICE"
              ADDITIONAL_PAGES_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ADDITIONAL_PAGES_PRICE & "<br />"
            Case Is = "ALBUM_BLOCK_PRICE"
              ALBUM_BLOCK_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ALBUM_BLOCK_PRICE & "<br />"
            Case Is = "COVER_PRICE"
              COVER_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COVER_PRICE & "<br />"
            Case Is = "COLOR_CORRECTION_PRICE"
              COLOR_CORRECTION_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & COLOR_CORRECTION_PRICE & "<br />"
            Case Is = "FINISHING_PRICE"
              FINISHING_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & FINISHING_PRICE & "<br />"
            Case Is = "ALBUM_PRICE"
              ALBUM_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ALBUM_PRICE & "<br />"
            Case Is = "CD_PRICE"
              CD_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & CD_PRICE & "<br />"
            Case Is = "ORDER_PRICE"
              ORDER_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ORDER_PRICE & "<br />"
            Case Is = "TAX_NAME_1"
              TAX_NAME_1 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_NAME_1 & "<br />"
            Case Is = "TAX_VALUE_1"
              TAX_VALUE_1 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_VALUE_1 & "<br />"
            Case Is = "TAX_NAME_2"
              TAX_NAME_2 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_NAME_2 & "<br />"
            Case Is = "TAX_VALUE_2"
              TAX_VALUE_2 = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TAX_VALUE_2 & "<br />"
            Case Is = "ORDER_PRICE_INCLUDING_TAXES"
              ORDER_PRICE_INCLUDING_TAXES = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & ORDER_PRICE_INCLUDING_TAXES & "<br />"
            Case Is = "SHIPMENT_PRICE"
              SHIPMENT_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & SHIPMENT_PRICE & "<br />"
            Case Is = "TOTAL_PRICE"
              TOTAL_PRICE = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & TOTAL_PRICE & "<br />"
            Case Is = "DISCOUNT"
              DISCOUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & DISCOUNT & "<br />"
            Case Is = "PAYED_AMOUNT"
              PAYED_AMOUNT = line.Replace(myVarsArray(i) & " = ", "")
              strTemp += myVarsArray(i) & " = " & PAYED_AMOUNT & "<br />"
            Case Else
              ' do nothing
          End Select
        End If
        
      Next
      
    End While
    
    ' Write our sanitised string back to the page, so we can verify against the source file that we parsed it correctly
    lblSanitisedOutput.Text = strTemp
    
    objStreamReader.Close()
    
    ' Next step, put the local variables into a database catalog, 
    ' but maybe we should attempt to parse the rows into correct data types expected by the db first. 
    ' for that we would need some table schema, field names, types, sizes etc...
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <b>Sanitised Output, which we now have in local variables.</b><br />
      <asp:label runat="server" id="lblSanitisedOutput" Font-Name="Verdana" />
    </div>
    </form>
</body>
</html>

Open in new window

Alan
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JCWEBHOST
ID: 38363225
Sorry
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38363270
Hey, no problem JCWEBHOST, these things happen; very pleased you persisted and posted it again!

You more comfortable with C# or VB?

Alan ";0)
0
 

Author Comment

by:JCWEBHOST
ID: 38363283
C# please
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38363315
C# version:
  public void Page_Load(object sender, EventArgs e)
  {


	string strTemp = "";
	string FIRST_NAME = "";
	string MIDDLE_NAME = "";
	string LAST_NAME = "";
	string PRODUCT_DETAILS = "";
	string PRICE_LEFT_DECIMAL_POINT = "";
	string PRICE_RIGHT_DECIMAL_POINT = "";
	string DATE_TIME = "";
	string STREET = "";
	string DISTRICT = "";
	string CITY = "";
	string ZIP = "";
	string STATE = "";
	string COUNTRY = "";
	string PHONE = "";
	string CELLULAR = "";
	string EMAIL = "";
	string COVER_MATERIAL = "";
	string ATTEMPT_TO_UPLOAD = "";
	string COVER_COLOR = "";
	string PAGE_COUNT = "";
	string COPIES = "";
	string COMMENT = "";
	string FINISHING = "";
	string COLOR_CORRECT = "";
	string IMAGE_COUNT = "";
	string CUSTOMER_ID = "";
	string CUSTOMER_TITLE = "";
	string CUSTOMER_BIRTHDATE = "";
	string USED_PRICING_FORMAT = "";
	string DECIMAL_SEPARATOR = "";
	string BASIC_PAGES_PRICE = "";
	string ADDITIONAL_PAGES_PRICE = "";
	string ALBUM_BLOCK_PRICE = "";
	string COVER_PRICE = "";
	string COLOR_CORRECTION_PRICE = "";
	string FINISHING_PRICE = "";
	string ALBUM_PRICE = "";
	string CD_PRICE = "";
	string ORDER_PRICE = "";
	string TAX_NAME_1 = "";
	string TAX_VALUE_1 = "";
	string TAX_NAME_2 = "";
	string TAX_VALUE_2 = "";
	string ORDER_PRICE_INCLUDING_TAXES = "";
	string SHIPMENT_PRICE = "";
	string TOTAL_PRICE = "";
	string DISCOUNT = "";
	string PAYED_AMOUNT = "";

	string[] myVarsArray = {"FIRST_NAME", "MIDDLE_NAME", "LAST_NAME", "PRODUCT_DETAILS", "PRICE_LEFT_DECIMAL_POINT", "PRICE_RIGHT_DECIMAL_POINT", "DATE_TIME", "STREET", "DISTRICT", "CITY", "ZIP", "STATE", "COUNTRY", "PHONE", "CELLULAR", "EMAIL", "COVER_MATERIAL", "ATTEMPT_TO_UPLOAD", "COVER_COLOR", "PAGE_COUNT", "COPIES", "COMMENT", "FINISHING", "COLOR_CORRECT", "IMAGE_COUNT", "CUSTOMER_ID", "CUSTOMER_TITLE", "CUSTOMER_BIRTHDATE", "USED_PRICING_FORMAT", "DECIMAL_SEPARATOR", "BASIC_PAGES_PRICE", "ADDITIONAL_PAGES_PRICE", "ALBUM_BLOCK_PRICE", "COVER_PRICE", "COLOR_CORRECTION_PRICE", "FINISHING_PRICE", "ALBUM_PRICE", "CD_PRICE", "ORDER_PRICE", "TAX_NAME_1", "TAX_VALUE_1", "TAX_NAME_2", "TAX_VALUE_2", "ORDER_PRICE_INCLUDING_TAXES", "SHIPMENT_PRICE", "TOTAL_PRICE", "DISCOUNT", "PAYED_AMOUNT"};

	//Open a file for reading
	string FILENAME = Server.MapPath("~/the-files-folder/TextFile.txt");

	//Get a StreamReader class that can be used to read the file
	StreamReader objStreamReader = null;
	objStreamReader = File.OpenText(FILENAME);

	//Now, read the entire file into a string
	string contents = ""; //objStreamReader.ReadToEnd()
	string line = "";
	while (!objStreamReader.EndOfStream)
	{
	  line = objStreamReader.ReadLine();

	  // sanitise the doublespaces and equals operators
	  line = line.Replace("  = ", " = ");
	  line = line.Replace(" =  ", " = ");
	  line = line.Replace(" =", " = ");
	  line = line.Replace("  ", " ");

	  // Populate our local variables
	  for (var i = 0; i < myVarsArray.Length; i++)
	  {
		if (line.Contains(myVarsArray(i) + " = "))
		{
		  switch (myVarsArray(i))
		  {
			case "FIRST_NAME":
			  FIRST_NAME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + FIRST_NAME + "<br />";
			  break;
			case "MIDDLE_NAME":
			  MIDDLE_NAME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + MIDDLE_NAME + "<br />";
			  break;
			case "LAST_NAME":
			  LAST_NAME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + LAST_NAME + "<br />";
			  break;
			case "PRODUCT_DETAILS":
			  PRODUCT_DETAILS = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PRODUCT_DETAILS + "<br />";
			  break;
			case "PRICE_LEFT_DECIMAL_POINT":
			  PRICE_LEFT_DECIMAL_POINT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PRICE_LEFT_DECIMAL_POINT + "<br />";
			  break;
			case "PRICE_RIGHT_DECIMAL_POINT":
			  PRICE_RIGHT_DECIMAL_POINT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PRICE_RIGHT_DECIMAL_POINT + "<br />";
			  break;
			case "DATE_TIME":
			  DATE_TIME = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DATE_TIME + "<br />";
			  break;
			case "STREET":
			  STREET = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + STREET + "<br />";
			  break;
			case "DISTRICT":
			  DISTRICT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DISTRICT + "<br />";
			  break;
			case "CITY":
			  CITY = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CITY + "<br />";
			  break;
			case "ZIP":
			  ZIP = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ZIP + "<br />";
			  break;
			case "STATE":
			  STATE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + STATE + "<br />";
			  break;
			case "COUNTRY":
			  COUNTRY = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COUNTRY + "<br />";
			  break;
			case "PHONE":
			  PHONE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PHONE + "<br />";
			  break;
			case "CELLULAR":
			  CELLULAR = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CELLULAR + "<br />";
			  break;
			case "EMAIL":
			  EMAIL = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + EMAIL + "<br />";
			  break;
			case "COVER_MATERIAL":
			  COVER_MATERIAL = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COVER_MATERIAL + "<br />";
			  break;
			case "ATTEMPT_TO_UPLOAD":
			  ATTEMPT_TO_UPLOAD = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ATTEMPT_TO_UPLOAD + "<br />";
			  break;
			case "COVER_COLOR":
			  COVER_COLOR = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COVER_COLOR + "<br />";
			  break;
			case "PAGE_COUNT":
			  PAGE_COUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PAGE_COUNT + "<br />";
			  break;
			case "COPIES":
			  COPIES = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COPIES + "<br />";
			  break;
			case "COMMENT":
			  COMMENT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COMMENT + "<br />";
			  break;
			case "FINISHING":
			  FINISHING = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + FINISHING + "<br />";
			  break;
			case "COLOR_CORRECT":
			  COLOR_CORRECT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COLOR_CORRECT + "<br />";
			  break;
			case "IMAGE_COUNT":
			  IMAGE_COUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + IMAGE_COUNT + "<br />";
			  break;
			case "CUSTOMER_ID":
			  CUSTOMER_ID = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CUSTOMER_ID + "<br />";
			  break;
			case "CUSTOMER_TITLE":
			  CUSTOMER_TITLE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CUSTOMER_TITLE + "<br />";
			  break;
			case "CUSTOMER_BIRTHDATE":
			  CUSTOMER_BIRTHDATE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CUSTOMER_BIRTHDATE + "<br />";
			  break;
			case "USED_PRICING_FORMAT":
			  USED_PRICING_FORMAT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + USED_PRICING_FORMAT + "<br />";
			  break;
			case "DECIMAL_SEPARATOR":
			  DECIMAL_SEPARATOR = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DECIMAL_SEPARATOR + "<br />";
			  break;
			case "BASIC_PAGES_PRICE":
			  BASIC_PAGES_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + BASIC_PAGES_PRICE + "<br />";
			  break;
			case "ADDITIONAL_PAGES_PRICE":
			  ADDITIONAL_PAGES_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ADDITIONAL_PAGES_PRICE + "<br />";
			  break;
			case "ALBUM_BLOCK_PRICE":
			  ALBUM_BLOCK_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ALBUM_BLOCK_PRICE + "<br />";
			  break;
			case "COVER_PRICE":
			  COVER_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COVER_PRICE + "<br />";
			  break;
			case "COLOR_CORRECTION_PRICE":
			  COLOR_CORRECTION_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + COLOR_CORRECTION_PRICE + "<br />";
			  break;
			case "FINISHING_PRICE":
			  FINISHING_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + FINISHING_PRICE + "<br />";
			  break;
			case "ALBUM_PRICE":
			  ALBUM_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ALBUM_PRICE + "<br />";
			  break;
			case "CD_PRICE":
			  CD_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + CD_PRICE + "<br />";
			  break;
			case "ORDER_PRICE":
			  ORDER_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ORDER_PRICE + "<br />";
			  break;
			case "TAX_NAME_1":
			  TAX_NAME_1 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_NAME_1 + "<br />";
			  break;
			case "TAX_VALUE_1":
			  TAX_VALUE_1 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_VALUE_1 + "<br />";
			  break;
			case "TAX_NAME_2":
			  TAX_NAME_2 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_NAME_2 + "<br />";
			  break;
			case "TAX_VALUE_2":
			  TAX_VALUE_2 = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TAX_VALUE_2 + "<br />";
			  break;
			case "ORDER_PRICE_INCLUDING_TAXES":
			  ORDER_PRICE_INCLUDING_TAXES = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + ORDER_PRICE_INCLUDING_TAXES + "<br />";
			  break;
			case "SHIPMENT_PRICE":
			  SHIPMENT_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + SHIPMENT_PRICE + "<br />";
			  break;
			case "TOTAL_PRICE":
			  TOTAL_PRICE = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + TOTAL_PRICE + "<br />";
			  break;
			case "DISCOUNT":
			  DISCOUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + DISCOUNT + "<br />";
			  break;
			case "PAYED_AMOUNT":
			  PAYED_AMOUNT = line.Replace(myVarsArray(i) + " = ", "");
			  strTemp += myVarsArray(i) + " = " + PAYED_AMOUNT + "<br />";
			  break;
			default:
			  // do nothing
			break;
		  }
		}

	  }

	}
    
    ' Write our sanitised string back to the page, so we can verify against the source file that we parsed it correctly
    lblSanitisedOutput.Text = strTemp
    
    objStreamReader.Close()
    
    ' Next step, put the local variables into a database catalog, 
    ' but maybe we should attempt to parse the rows into correct data types expected by the db first. 
    ' for that we would need some table schema, field names, types, sizes etc...
  End Sub

Open in new window

Alan ";0)
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38363330
Hi JCWEBHOST,
if you want to take this further, will need some schema for the destination table/tables, so we can convert the values from the input file to the db expected types and sizes.

Respectfully yours,
Alan
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38363333
That huge code is really not necessary, an array and a for loop would reduce that to 20 lines or less.
0
 

Author Comment

by:JCWEBHOST
ID: 38363406
Can you show me how to loop and reduce the code?
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38363509
Sure it's doable, that was first draft; but, Me too ";0)
0
 

Author Comment

by:JCWEBHOST
ID: 38363568
Doable what?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 38363862
I have removed the repetitive code but I still don't like the solution. The way to manage the = sign can be better (using split and trim).

  public void Page_Load(object sender, EventArgs e)
  {
	string[] myVarsArray = {"FIRST_NAME", "MIDDLE_NAME", "LAST_NAME", "PRODUCT_DETAILS", "PRICE_LEFT_DECIMAL_POINT", "PRICE_RIGHT_DECIMAL_POINT", "DATE_TIME", "STREET", "DISTRICT", "CITY", "ZIP", "STATE", "COUNTRY", "PHONE", "CELLULAR", "EMAIL", "COVER_MATERIAL", "ATTEMPT_TO_UPLOAD", "COVER_COLOR", "PAGE_COUNT", "COPIES", "COMMENT", "FINISHING", "COLOR_CORRECT", "IMAGE_COUNT", "CUSTOMER_ID", "CUSTOMER_TITLE", "CUSTOMER_BIRTHDATE", "USED_PRICING_FORMAT", "DECIMAL_SEPARATOR", "BASIC_PAGES_PRICE", "ADDITIONAL_PAGES_PRICE", "ALBUM_BLOCK_PRICE", "COVER_PRICE", "COLOR_CORRECTION_PRICE", "FINISHING_PRICE", "ALBUM_PRICE", "CD_PRICE", "ORDER_PRICE", "TAX_NAME_1", "TAX_VALUE_1", "TAX_NAME_2", "TAX_VALUE_2", "ORDER_PRICE_INCLUDING_TAXES", "SHIPMENT_PRICE", "TOTAL_PRICE", "DISCOUNT", "PAYED_AMOUNT"};

	string FILENAME = Server.MapPath("~/the-files-folder/TextFile.txt");
	StreamReader objStreamReader = null;
	objStreamReader = File.OpenText(FILENAME);

	string contents = ""; //objStreamReader.ReadToEnd()
	string line = "";
	while (!objStreamReader.EndOfStream)
	{
	  line = objStreamReader.ReadLine();

	  // sanitise the doublespaces and equals operators
	  line = line.Replace("  = ", " = ");
	  line = line.Replace(" =  ", " = ");
	  line = line.Replace(" =", " = ");
	  line = line.Replace("  ", " ");

	  var dict = new Dictionary<string, string>();

	  // Populate our local variables
	  for (var i = 0; i < myVarsArray.Length; i++)
	  {
	    string varname = myVarsArray(i);
	    if (line.Contains(varname + " = "))
	    {
	       strTemp += varname + " = " + line.Replace(myVarsArray(i) + " = ", "") + "<br />";
	    }
	  }
	}
 
    lblSanitisedOutput.Text = strTemp
    
    objStreamReader.Close()
  }

Open in new window

0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 38375453
I've requested that this question be deleted for the following reason:

Reason: JCWEBHOST, <br />It appears as though you have posted duplicate questions. <br /><br />All Experts are advised to post their suggestions here: <br /><a href="http://www.experts-exchange.com/Q_27852027.html">http://www.experts-exchange.com/Q_27852027.html</a> <br /><br />This version of the question is being deleted. <br /><br />Vee_Mod <br />Experts Exchange Moderator<br />
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38365830
Hi Vee_Mod,
I would have thought you would delete the other question, being as it has attracted little participation, whereas this one is alive and kicking.

Alan
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 2000 total points
ID: 38365880
@jaimie,
your code doesn't parse the values of the text file, it just reads each line back exactly as it is in the text file.

You could do the same like this:
	string strTemp = "";

	string[] myVarsArray = {"FIRST_NAME", "MIDDLE_NAME", "LAST_NAME", "PRODUCT_DETAILS", "PRICE_LEFT_DECIMAL_POINT", "PRICE_RIGHT_DECIMAL_POINT", "DATE_TIME", "STREET", "DISTRICT", "CITY", "ZIP", "STATE", "COUNTRY", "PHONE", "CELLULAR", "EMAIL", "COVER_MATERIAL", "ATTEMPT_TO_UPLOAD", "COVER_COLOR", "PAGE_COUNT", "COPIES", "COMMENT", "FINISHING", "COLOR_CORRECT", "IMAGE_COUNT", "CUSTOMER_ID", "CUSTOMER_TITLE", "CUSTOMER_BIRTHDATE", "USED_PRICING_FORMAT", "DECIMAL_SEPARATOR", "BASIC_PAGES_PRICE", "ADDITIONAL_PAGES_PRICE", "ALBUM_BLOCK_PRICE", "COVER_PRICE", "COLOR_CORRECTION_PRICE", "FINISHING_PRICE", "ALBUM_PRICE", "CD_PRICE", "ORDER_PRICE", "TAX_NAME_1", "TAX_VALUE_1", "TAX_NAME_2", "TAX_VALUE_2", "ORDER_PRICE_INCLUDING_TAXES", "SHIPMENT_PRICE", "TOTAL_PRICE", "DISCOUNT", "PAYED_AMOUNT"};

	string FILENAME = Server.MapPath("~/the-files-folder/TextFile.txt");
	StreamReader objStreamReader = null;
	objStreamReader = File.OpenText(FILENAME);

	string contents = objStreamReader.ReadToEnd();
	lblSanitisedOutput.Text = contents.Replace(Environment.NewLine, "<br />");

	objStreamReader.Close();
  }

Open in new window

Alan
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38366081
@Vee_Mod,
no problem, have done as requested, but the thread seems to have lost continuity.
how do we get the comments in the right order to maintain the flow that existed in this thread?

Respectfully yours,
Alan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question