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
Printable View
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
Are all the strings the same?
Like is the text file:
String
String1
String2
String3
Or are they different:
String
Llama1
Horse9
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?
there different the only thing is the same iswhich seperates themQuote:
|
Try using Split?
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.
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
strOrig = Replace(strOrig, "|", vbNewLine)
strOrig = Replace(strOrig, Space(1), vbNullString)
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.Quote:
Originally Posted by DeCo
DeCo: No, you're going to end up with an array of words, each word in a different element of the array
strArray(0) = FredCode:Dim strArray() As String
strArray = Split("Fred|Joe|Harry" ,"|")
strArray(1) = Joe
strArray(2) = Harry
whats strOrig?
strOrig = 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.Quote:
Originally Posted by LaVolpe
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$ :bigyello:
when command1 execute's text1 completely erases?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
Declare strtext in the Declarations section of the form. Vis:
But see Post #13Code: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
I know thats happening to me atm im trying to fix it lolQuote:
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.