Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my input text file format

SHIPPER/EXPORTER (2)                                        DOCUMENT NO (5)
EXXON MOBIL CORPORATION                                  NAM2998573      NAM2998573                       
22777 SPRINGWOODS VILLAGE PARKWAY                        EXPORT REFERENCES (6)
SPRING, TX 77389-1425 USA                                5004753 / 6004754
                                                           4451690406

 CONSIGNEE (3)                                       FORWARDING AGENT - REFERENCES (7)
MANULI DA AMAZONIA                                E LOGISTICS INC (931839)
INDUSTRIA DE EMBALAGENS LTDA AV.                 3050 POST OAK BLVD, STE 444   CHB:
BURITI 3670 BAIRRO DISTRITO                           HOUSTON, TX 77056    FMC: 025823        
INDUSTRIAL 69075-000 MANAUS, AM                   TEL. NO. 346-802-4008
BRASIL
 CNPJ/CPF: 14269557000137

NOTIFY (4)                                        POINT AND COUNTRY OF ORIGIN (8)
MANULI DA AMAZONIA
INDUSTRIA DE EMBALAGENS LTDA AV.                    UNITED STATES
BURITI 3670 BAIRRO DISTRITO                DOMESTIC ROUTING/EXPORT INSTRUCTIONS (9)
INDUSTRIAL 69075-000 MANAUS, A              NO SED REQUIRED - X20180206869589
BRASIL CNPJ: 14.269.557/0001-37




Note: i want to read and extract first Shipper/Exporter sub-string values.

in my program code when i am reading shipper exporter values its reading document no and export reference values also.
so here when i am reading shipper exporter header name and values i want to skip document no and export reference header name and values

so please kindly give me a solution for this

i want to show my output like in this format

SHIPPER/EXPORTER (2)
EXXON MOBIL CORPORATION
22777 SPRINGWOODS VILLAGE PARKWAY
SPRING, TX 77389-1425 USA

What I have tried:

<pre>
static void Main(string[] args)
{
string text = System.IO.File.ReadAllText(@"D:\data.txt");
int i = text.IndexOf("Shipper/Exopter");
string shipperexpoter = text.Substring(i+15,80);
System.IO.File.WriteAllText(@"D:\output.txt", "Shipper/Exopter="+shipperexpoter);
Console.WriteLine("Shipper/Expoter =" +shipperexpoter);
Console.Read();
Posted
Updated 12-Mar-18 21:33pm
v2
Comments
BillWoodruff 3-Mar-18 20:40pm    
You need to have some regular structure in the data to clearly delimit objects and attributes, or use AI.
Member 13706320 4-Mar-18 4:26am    
how? can you give give a steps?
Member 13706320 4-Mar-18 4:56am    
its impossible to get sub-string values because in the input text file
Header Name Shipper/EXporter (2) in the same line another name Document No after next line Sub-string values of Shipper/Exporter in the same line sub-string of Document no after so how could it possible to get the value of Sub-String

1 solution

You need to start by looking a lot closer at your text file, and work out what distinguishes the stuff on the left from the stuff on the right. If it's always spaces, and the right hand stuff always starts in the same column, then that's just a Substring job similar to the one line you show. If it isn't, then it gets more complex and you need to work out how to identify it properly. Don't just assume that "it always starts in column 40" because it shows that way in your text editor - it may use tabs to "move it across" and if so then Substring won't work correctly.

Then stop reading the text inst a string, and read it as lines:
string[] lines = File.ReadAllLines(@"D:\data.txt");
Then use a loop to examine each line until you find one starting with "SHIPPER/EXPORTER"
You can then process the following lines to extract the address info before continuing to see if there are more exporters in there.
 
Share this answer
 
v2
Comments
Member 13706320 3-Mar-18 7:15am    
No there is no Shipper/exporters in the 1 page. can you give a brief program for this to me i can try it so please kindly do the needful.
OriginalGriff 3-Mar-18 7:19am    
No, it's your homework - we are willing to help you, but not do it all for you!
Member 13706320 3-Mar-18 7:32am    
Anyway thanks for your comments i don't want to use int i to string.substring to split the i values i am right.
i have to use loop condition over there right.
OriginalGriff 3-Mar-18 7:43am    
Without looking at your actual data I can't tell - but you probably need both: a loop to split out multiple lines and Substring inside that loop.
Member 13706320 3-Mar-18 8:02am    
what is the way to show you my file so please help me on this i have to complete this work asap

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