hi
i have one txt file that contain data like this
11111111,22222222
22222222,33333333
33333333,44444444
what im trying to do is to make 2 new txt files and to store first 8 characters into first txt and second 8 chars into second txt ... " , " should be excluded
can anyone help me with this
thanks in advice
kristina
6 1145
hi
i have one txt file that contain data like this
...
can anyone help me with this
thanks in advice
kristina
Hi Kristina,
sure, use the MID function to take the part of the string you want
lets say you have Srt1 and Str2 as strings, and
Str1= 12345678,12345678
with MID:
Strt2= mid(str1,1,8) '(base string, starting position, length)
you will have Str2= 12345678
other example:
Str3 = ("hello world",3, 5)
will make Str3 = "llo w"
a more general way will be using also INSTR
HTH
it works
thank you so much
I think this should get you what you want. - Dim file_stream As IO.FileStream
-
Dim bytes As Byte()
-
Dim myArray() As String
-
Dim strLine As String
-
-
Dim stream_reader = New System.IO.StreamReader("c:\test0.txt") ' Change path to your source file
-
While stream_reader.Peek() >= 0
-
strLine = stream_reader.readline()
-
myArray = Split(strLine, ",")
-
-
file_stream = New IO.FileStream("c:\test1.txt", IO.FileMode.Append) 'Change path to the file for the first value
-
bytes = New System.Text.UTF8Encoding().GetBytes(myArray(0) & vbCrLf)
-
file_stream.Write(bytes, 0, bytes.Length)
-
file_stream.Close()
-
-
file_stream = New IO.FileStream("c:\test2.txt", IO.FileMode.Append) 'Change path to the file for the second value
-
bytes = New System.Text.UTF8Encoding().GetBytes(myArray(1) & vbCrLf)
-
file_stream.Write(bytes, 0, bytes.Length)
-
file_stream.Close()
-
End While
-
-
MessageBox.Show("Done")
Torgg
Or you could parse it in one line of code
Dim arrayValues() As String = Split("33333333,44444444", ",")
MsgBox(arrayValues(0))
MsgBox(arrayValues(1))
Torgg
I done it and there is the code - Dim str1 As String
-
Dim str2 As String
-
Dim str3 As String
-
Open "c:\1a.pair" For Input As #1 'original file
-
Open "c:\11.pair" For Output As #2 'new file
-
Open "c:\12.pair" For Output As #3
-
Do Until EOF(1) 'read in file until done
-
Line Input #1, str1
-
str2 = Mid(str1, 1, 32)
-
str3 = Mid(str1, 34, 32)
-
Print #2, str2
-
Print #3, str3
-
Loop
-
Close #1
-
Close #2
-
Close #3
Thanks once again.
str2 = Mid(str1, 1, 32)
str3 = Mid(str1, 34, 32)
I see the specs changed somewhat, along the way. This is where the Split() function would have an advantage, of course - you wouldn't need to recode if the length of the fields changes.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matt L. |
last post by:
In summary, I don't know how/why the following code works and would like to
know.
I'm trying to match the first 3 characters of a variable (filename). The
code below crudely works, but only if I...
|
by: EJH |
last post by:
I have a Database that has three tables. One of the three is just a table
that contains three fields and is filled with reference information. One
field is 3-Digit(primary key), the next is...
|
by: K |
last post by:
I've an XML file in UTF-8.
It contains some chinese characters ( both simplified chinese and
traditional chinese).
In loading the XML file with MSXML parser, I used the below code to retrieve...
|
by: Ze Coder |
last post by:
Hello, I would like to know how to split a string variable in x
lines(possibly an array) of a maximum length of 30 chrs, but without
truncating words.
I Think there's a trick to do with...
|
by: Slavo Smutny |
last post by:
Hi,
which is better approach to store my JavaScript code, to store it in
separate .js file
or to embed the code within HTML attributes (e.g. <p
onclick="javascript:submit();">click this</p>)?
I...
|
by: hagar |
last post by:
Hi all,
I have a problem which I can not understand why this is happening!
Debugging this I actually see that it grabs first record then when stepping through code to the line rsImportTo.AddNew...
|
by: Registered User |
last post by:
Hi experts,
I'm trying to write a program to solve the following exercise:
Accept three strings from the user. Find the first occurrence of the
first string in the third string. If it is present...
|
by: cs |
last post by:
Hi,
I'm new to C and would appreciate any feedback on the following
program, asplit, which splits a file into 2 new files, putting a
certain number of lines in the first file, and all the rest...
|
by: Dennis |
last post by:
Hi, I have a text file that contents a list of email addresses like
this:
"foo@yahoo.com"
"tom@hotmail.com"
"jerry@gmail.com"
"tommy@apple.com"
I like to
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |