473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

reading a text file with spaces

15
I have a text file containing many lines of numbers seperated by spaces. example:
1234 34332 12
1235 3543 12
I need to read the file into a 2-d array I dont know how to do this becasue of the spaces. I need to replace the spaces in that file with commas, so i can do this. or anyother way that is possible..
Nov 28 '09 #1
5 2924
vb5prgrmr
305 Expert 100+
Use the replace function when you read it in. If you do not know how to read a file in with VB 6.0, the please look up the following on the index tab of vb's help...

FreeFile Function
Open Statement
Input Function
Line Input Function
Close Statement
Replace Function
Split Function



Good Luck
Nov 29 '09 #2
!NoItAll
297 100+
Also look up the split function. Very handy for just what you are doing.
Nov 29 '09 #3
vb5prgrmr
305 Expert 100+
Ah-hmm (clears throat and then whispers) Psstt! Hey NoItAll, look at the line right above my Good Luck :)
Nov 29 '09 #4
!NoItAll
297 100+
DOH!

...he said with an embarrassed red-faced......

Don't forget the ! in front of NoItAll, it is meant, and proven here, as the "not" symbol in my pseudonym...
Nov 29 '09 #5
vb5prgrmr
305 Expert 100+
dawn123,

Recieved your PM...

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4.  
  5. On Error GoTo Command1_ClickError
  6.  
  7. Dim FName As String, FNumb As Integer
  8. Dim LineContents As String, LineElements() As String
  9. Dim LowerBoundsOfArray As Integer, UpperBoundsOfArray As Integer, ForLoopCounter As Integer
  10.  
  11. CD.CancelError = True
  12. CD.Filter = "Text Files *.txt|*.txt"
  13. CD.ShowOpen
  14.  
  15. FNumb = FreeFile
  16. FName = CD.FileName
  17.  
  18. Open FName For Input As #FNumb
  19. Do While Not EOF(FNumb)
  20.   Line Input #FNumb, LineContents
  21.   LineElements = Split(LineContents, " ")
  22.   'do work here with information from file LineElements(0), LineElements(1), LineElements(2)
  23.   'you may also want to use the LBound and UBound Functions...
  24. '  LowerBoundsOfArray = LBound(LineElements)
  25. '  UpperBoundsOfArray = UBound(LineElements)
  26. '  For ForLoopCounter = LowerBoundsOfArray To UpperBoundsOfArray
  27. '    'do work here
  28. '  Next ForLoopCounter
  29. Loop
  30. Close #FNumb
  31.  
  32. Exit Sub
  33. Command1_ClickError:
  34.  
  35. If Err.Number = 32755 Then Exit Sub 'user pressed cancel
  36.  
  37. End Sub
  38.  
Just for starters... Now, as for replacing those space characters with commas, you can either use the replace function as I mentioned and remove the Split Function from my example code, or you can use the Join Function and keep my example split function, however I must note that this would be much slower than use the replace function.



Good Luck
Nov 30 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
9
by: EkteGjetost | last post by:
I would like to first apologize to those of you who read my last post "desperately need help". As a regular on other forums i can understand how aggravating it would be to have someone come on who...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
10
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
5
by: aboxylica | last post by:
I have a file which contains something like this >ref|NC_001133| CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACA CATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTT...
4
by: Laharl | last post by:
My Operating Systems professor has assigned homework that basically boils down to implementing ls -lra, but with a different output format. In other words, list the files and subdirectories (and a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.