Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Write the FT1 segement to another text file

Posted on 2006-11-29
15
Medium Priority
?
279 Views
Last Modified: 2010-04-16
I have a hl7 messgae like below ( HL7.txt)

MSH|^~\&|TIME-Db|sssssss-rainsrv|FOCUS 2000|4|20061129||DFT^P03|1|P|2.2|||SU|SU|
EVN|P03|20061129||APP|
PID|1||1000179||ffff^ffff||1967889|F||A|22222 ggggg^^^CA^92666||11111111|||M|||111111111||||||||
OBX|1|ST|HGB^Hemoglobin||12.7|||||||||20061113
OBX|2||HGT||154.94|||||||||
FT1|1|||20061120|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||
MSH|^~\&|TIME-Db|sssssss-rainsrv|FOCUS 2000|4|20061129||DFT^P03|2|P|2.2|||SU|SU|
EVN|P03|20061129||APP|
PID|1||1000179||DddddE^ddd||194444|F||A|222 gggg^^^CA^92666||666666666|||M|||5555555||||||||
OBX|1|ST|HGB^Hemoglobin||12.7|||||||||20061113
OBX|2||HGT||154.94|||||||||
FT1|1|||20061121|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||
..
..etc

I would like to grab only the line start with FT1 and write it to another text file ( result.txt).

the result should look like below
FT1|1|||20061120|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||
FT1|1|||20061121|20061129|CG|CAPD^CAPD DAILY EXCHANGE (METHOD I)^^N^N|||1|0||A01||||||585.6^^||||

How can I do this?
0
Comment
Question by:jung1975
  • 5
  • 5
  • 3
13 Comments
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 800 total points
ID: 18040618
Well if you have it in a string you can do a split on the return character

string textfile; // Load your textfile into this one
string results = "";
foreach(string line in textfile.split(Environment.NewLine))
{
if line.StartsWith("FT1")
results += line + Environment.NewLine;
}

results now contains only lines starting with FT1
0
 

Author Comment

by:jung1975
ID: 18040634
thanks...

How can I load the source text file ( it;s in c:\hl7.txt) ?

how cna I write result to the text file ( c:\result.txt)?

0
 

Author Comment

by:jung1975
ID: 18040802
If I do like below , I am getting errors:  what am i doing wrong?
Error      1      The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
Error      2      Argument '1': cannot convert from 'string' to 'char[]'      


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string textfile = @"C:\HL7.txt"; // Load your textfile into this one
         string results = "";
           foreach(string line in textfile.Split(Environment.NewLine))
        {
             if (line.StartsWith("FT1"))
                results += line + Environment.NewLine;
          }

          TextBox1.Text = results;
    }
}
-

Error      1      The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
\Error      2      Argument '1': cannot convert from 'string' to 'char[]'      
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!

 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1200 total points
ID: 18041279
You may try to pass:

Environment.NewLine.ToCharArray();

This should work.

However, I'm a bit concern about Enviroment.NewLine.

I am not 100% sure, but from my little experience with Hl7 I'd say lines are separatedby "\r" (or "\n" ?) character,
not by "\r\n" (which is Enviroment.NewLine).
New line is the last character in the entire message (messages are separated by "\r\n").
This may cause some problems later if you neglect proper separation characters.
I can't remember details however definitely had some bad experience :)
0
 

Author Comment

by:jung1975
ID: 18041345
thanks it doesn't give any errors,but it doesnt write anything in textbox1???
0
 

Author Comment

by:jung1975
ID: 18041569
i think it;s becuase Enviroment.NewLine..... how can i fix this issue?
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 800 total points
ID: 18042122
It is possible depending on the source that there is only \r or \n as mentioned by anarki_jimbel.

Try playing with different characters for the split.
0
 
LVL 30

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 1200 total points
ID: 18042715
Yeah, just change to :

          textfile.split("\n")
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 18046461
Use single quotes not double quotes:

textfile.split('\n');
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 18048684
Yes, sorry :)
0
 

Author Comment

by:jung1975
ID: 18055799
I didi something like below but still no result in the textbox. it;s just blank
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string textfile = @"C:\hl7test.txt"; // Load your textfile into this one
         string results = "";
         foreach (string line in textfile.Split('\n'))
        {
            if (line.StartsWith("FT1"))
                results += line;
          }

          TextBox1.Text = results;
    }
}
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1200 total points
ID: 18064416

Did you try same with '\r' ("carriage return") character?:
foreach (string line in textfile.Split('\r'))

According to
http://publib.boulder.ibm.com/infocenter/wbihelp/v6rxmx/index.jsp?topic=/com.ibm.wbia_adapters.doc/doc/healthcare/hl7mst73.htm they use <cr> as a line delimeter.
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 18064460
Checked some more. From

http://www.microsoft.com/technet/prodtechnol/biztalk/2006/library/hl7/c92e2f70-0bfa-4bc8-8044-4a6e62cabee3.mspx?mfr=true

it follows:

"... the segment delimiter is <CR> or <CR><LF> (optional for the last segment)"

<cr> == '\r', <lf>=='\n'

Enviroment.NewLine == '\r\n'

I believe the first case is most probable..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

876 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