|
-
Jan 6th, 2008, 12:29 AM
#1
Thread Starter
Addicted Member
Reorganizing text file
hey i have a very large file and well the format SUCKS lol its like
name | name2 | name3 | name4 | name5 | ect ect
How can i make it so i can reorganize the list to
name
name2
name3
name4
ect ect
-
Jan 6th, 2008, 12:30 AM
#2
Frenzied Member
Re: Reorganizing text file
Are all the strings the same?
Like is the text file:
String
String1
String2
String3
Or are they different:
String
Llama1
Horse9
-
Jan 6th, 2008, 12:32 AM
#3
Re: Reorganizing text file
If the names are delimited then it would be relatively easy. Are those bars you showed us actually in the file? If not, what characters are between the names?
-
Jan 6th, 2008, 12:32 AM
#4
Thread Starter
Addicted Member
Re: Reorganizing text file
there different the only thing is the same is which seperates them
-
Jan 6th, 2008, 12:35 AM
#5
Frenzied Member
Re: Reorganizing text file
-
Jan 6th, 2008, 12:35 AM
#6
Re: Reorganizing text file
If the bar is in there, then it should be very simple.
1. Read the text file, either in total or line by line
2. Replace the bars with carriage returns
3. Save the text to a new file
P.S. Using a delimiter is not necessarily a bad file format -- really it is a very usable format. If you think about it, a name on each line is basically the same thing; only the delimiter is a carriage return vs a bar.
Last edited by LaVolpe; Jan 6th, 2008 at 12:46 AM.
-
Jan 6th, 2008, 12:40 AM
#7
Thread Starter
Addicted Member
Re: Reorganizing text file
how would i go about making a new line once it removes it? because if i just use the split function im going to end up with stringstring1string2string3 ect ect lol
-
Jan 6th, 2008, 12:42 AM
#8
Frenzied Member
Re: Reorganizing text file
strOrig = Replace(strOrig, "|", vbNewLine)
strOrig = Replace(strOrig, Space(1), vbNullString)
-
Jan 6th, 2008, 12:44 AM
#9
Re: Reorganizing text file
 Originally Posted by DeCo
how would i go about making a new line once it removes it? because if i just use the split function im going to end up with stringstring1string2string3 ect ect lol
Actually Split could be used, but a simpler method, on second thought, might just be to use VB's Replace$(). Read the text and replace | with vbCrLf. Then save the modified text.
-
Jan 6th, 2008, 12:45 AM
#10
Re: Reorganizing text file
DeCo: No, you're going to end up with an array of words, each word in a different element of the array
Code:
Dim strArray() As String
strArray = Split("Fred|Joe|Harry" ,"|")
strArray(0) = Fred
strArray(1) = Joe
strArray(2) = Harry
-
Jan 6th, 2008, 12:48 AM
#11
Thread Starter
Addicted Member
Re: Reorganizing text file
-
Jan 6th, 2008, 12:50 AM
#12
Frenzied Member
Re: Reorganizing text file
-
Jan 6th, 2008, 01:09 AM
#13
Re: Reorganizing text file
 Originally Posted by LaVolpe
Actually Split could be used, but a simpler method, on second thought, might just be to use VB's Replace$(). Read the text and replace | with vbCrLf. Then save the modified text.
One issue is whether there's a terminating "|" at the end of each line. If there is, then Replace will be ok, if not, then you'll get names running into each other.
eg
Line 1: Fred!Joe
Line 2: Harry|Bert
after Replace (with vbCrLf):
Fred
JoeHarry
Bert
and if there is a trailing "|" then Split will return an extra element of the array with a null value.
eg
Line1: Fred|Joe|
Line2: Harry|Bert|
after Split to array:
array(0) = Fred
array(1) = Joe
array(2) = Harry
array(3) = Bert
array(4) = null
Not a major issue, but one to watch out for.
EDIT: and if there's a mixture then it's back to good old InStr and Mid$
Last edited by Doogle; Jan 6th, 2008 at 01:32 AM.
Reason: Too many nulls
-
Jan 6th, 2008, 01:15 AM
#14
Thread Starter
Addicted Member
Re: Reorganizing text file
Code:
Private Sub Form_Load()
Open App.Path & "\1.txt" For Input As #1
Input #1, strtext
Text1.Text = strtext
End Sub
Private Sub Command1_Click()
strtext = Replace(strtext, "|", vbNewLine)
strtext = Replace(strtext, Space(1), vbNullString)
Text1.Text = strtext
End Sub
when command1 execute's text1 completely erases?
-
Jan 6th, 2008, 01:18 AM
#15
Re: Reorganizing text file
Declare strtext in the Declarations section of the form. Vis:
Code:
Private strtext As String
Private Sub Form_Load()
Open App.Path & "\1.txt" For Input As #1
Input #1, strtext
Text1.Text = strtext
End Sub
Private Sub Command1_Click()
strtext = Replace(strtext, "|", vbNewLine)
strtext = Replace(strtext, Space(1), vbNullString)
Text1.Text = strtext
End Sub
But see Post #13
-
Jan 6th, 2008, 01:33 AM
#16
Thread Starter
Addicted Member
Re: Reorganizing text file
One issue is whether there's a terminating "|" at the end of each line. If there is, then Replace will be ok, if not, then you'll get names running into each other.
I know thats happening to me atm im trying to fix it lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|