Sat80
asked on
Cutting the first three characters of each line
Hi Experts,
I have a text file that includes different lines and an each line there is some elements divided by a comma (,):
ABC1235,ASD45,A2R45546=4
V5R48654=,TR4548
R58sgd%$,YT841d4,ABC127
What I want is that, I would to load that text file and then cut each element after the third character. So, the final result should be something like this:
ABC,ASD,A2R
V5R,TR4
R58,YT8,ABC
As you can see the above result is cutting each element (the elements divided by comma ,) and then rewrite the output data to the same file.
Thanks in advance
Regards
I have a text file that includes different lines and an each line there is some elements divided by a comma (,):
ABC1235,ASD45,A2R45546=4
V5R48654=,TR4548
R58sgd%$,YT841d4,ABC127
What I want is that, I would to load that text file and then cut each element after the third character. So, the final result should be something like this:
ABC,ASD,A2R
V5R,TR4
R58,YT8,ABC
As you can see the above result is cutting each element (the elements divided by comma ,) and then rewrite the output data to the same file.
Thanks in advance
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry misread, I understood the string-requirement.
You need to adjust this:
Do Until sInputLine is Nothing
sOutput += sInputLine.Substring(3, sInputLine.Length() - 3)
sInputLine = srFileReader.ReadLine()
Loop
into
dim sInput as string()
Do Until sInputLine is Nothing
sInput = sinputLine.split(',')
For i = 0 To UBound(aryTextFile)
sInput(i) = sInput(i).Substring(3, sInput(i)Length() - 3)
Next i
sOutput += String.Join(",", sInput)
sInputLine = srFileReader.ReadLine()
Loop
You need to adjust this:
Do Until sInputLine is Nothing
sOutput += sInputLine.Substring(3, sInputLine.Length() - 3)
sInputLine = srFileReader.ReadLine()
Loop
into
dim sInput as string()
Do Until sInputLine is Nothing
sInput = sinputLine.split(',')
For i = 0 To UBound(aryTextFile)
sInput(i) = sInput(i).Substring(3, sInput(i)Length() - 3)
Next i
sOutput += String.Join(",", sInput)
sInputLine = srFileReader.ReadLine()
Loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all
NP. Glad to help : )
That was fun, how many ways???
1. Read the file line by line
2. use the string.substring-method on that line http://msdn.microsoft.com/en-us/library/aka44szs.aspx
3. save everything back into the file
Open in new window