473,396 Members | 1,784 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,396 software developers and data experts.

Split a text file

I want to slipt the following data ....


189{405.7}25{406.7}1{409.7}2{1.7}909<02.01.138.000 .9>{0.11}532756{401.7}2{402.7}0{403.7}1{404.12}185 .2{405.7}25{406.7}1{409.7}3{1.7}909<02.01.138.000. 9>{0.11}532756{401.7}2{402.7}1{403.7}1{404.12}191{ 405.7}50{406.7}1{409.7}3{1.7}909<02.01.138.000.9>{ 0.11}532756{401.7}2{402.7}0{403.7}1{404.12}185.1{4 05.7}10{406.7}1{409.7}4{1.7}909<02.01.138.000.9>{0 .11}532756{401.7}2{402.7}1{403.7}1{404.12}191.8{40 5.7}500{406.7}1{409.7}4{1.7}909...
Nov 3 '07 #1
12 1424
QVeen72
1,445 Expert 1GB
Hi,

use "Split" function..

Regards
Veena
Nov 3 '07 #2
Ali Rizwan
925 512MB
Hi,
With which key word you want to split the text.
Did you want to split the text after every . or { or text between them.

GOOD LUCK
ALI
Nov 3 '07 #3
9815402440
180 100+
hi priyanka

try this code


Const a = "189{405.7}25{406.7}1{409.7}2{1.7}909<02.01.138.00 0.9>{0.11}532756{401.7}2{402.7}0{403.7}1{404.12}18 5.2{ 405.7}25{406.7}1{409.7}3{1.7}909<02.01.138.000.9>{ 0.11}532756{401.7}2{402.7}1{403.7}1{404.12}191{40 5.7}50{406.7}1{409.7}3{1.7}909<02.01.138.000.9>{0. 11}532756{401.7}2{402.7}0{403.7}1{404.12}185.1{ 405.7}10{406.7}1{409.7}4{1.7}909<02.01.138.000.9>{ 0.11}532756{401.7}2{402.7}1{403.7}1{404.12}191.8{ 405.7}500{406.7}1{409.7}4{1.7}"
Dim varBFR
Dim varBFR1
Dim varBFR2

varBFR = Split(a, ">")
Dim i As Integer
Dim ii As Integer
Dim iii As Integer
For i = 0 To UBound(varBFR)
varBFR1 = Split(varBFR(i), "<")
For ii = 0 To UBound(varBFR1)
varBFR2 = Split(varBFR1(ii), "}")
For iii = 0 To UBound(varBFR2)
Debug.Print varBFR2(iii) & IIf(InStr(1, varBFR2(iii), "{", vbTextCompare) > 0, "}", "")
Next
Next
Next

regards
manpreet singh dhillon hoshiarpur
Nov 5 '07 #4
Hey thanks guys actually this data save in text file n i have to crunch the data

From following data i want to retrive the values like
"189{405.7}25{406.7}1{409.7}2{1.7}909<02.01.138.00 0.9>{0.11}532756{401.7}2{402.7}0{403.7}1{404.12}18 5.2{ 405.7}25{406.7}1{409.7}3{1.7}



189
25
1
2
909
532756
2
0....
so on

Thank you
please help its urgent
Nov 5 '07 #5
9815402440
180 100+
hi priyanka
try following code

Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.OpenTextFile("F:\Documents and Settings\XPPRESP3\My Documents\1.txt")
Dim varBFR
While Not ts.AtEndOfStream
varBFR = Split(ts.ReadLine, "}")
Dim i As Integer
For i = 0 To UBound(varBFR)
Debug.Print Val(varBFR(i))
Next
Wend


regards
manpreet singh dhillon hoshiarpur
Nov 5 '07 #6
Hey thanks manpreet, but it is giving error " complier error" near Set ts = fso.OpenTextFile("C:\rawdata.txt").....help me please
Nov 5 '07 #7
9815402440
180 100+
hi priyanka

add refererence to Microsoft Scripting Runtime. to do this open Project Menu and select Reference option


regards
manpreet singh dhillon hoshiarpur
Nov 5 '07 #8
m attaching the text file just check withy dat
Attached Files
File Type: txt rawdata1.txt (8.6 KB, 357 views)
Nov 5 '07 #9
hey but its not provide the proper values...
Nov 5 '07 #10
QVeen72
1,445 Expert 1GB
Hi Priyanka,

use this code:
Add a ListBox Control to ur Form and Check:

Expand|Select|Wrap|Line Numbers
  1.     Dim MyStr As String
  2.     Dim TArr
  3.     Dim i As Long
  4.     Dim j As Long
  5.     Dim TempStr As String
  6.     '
  7.     List1.Clear
  8.     MyStr = "189{405.7}25{406.7}1{409.7}2{1.7}909<02.01.138.000.9>{0.11}532756{401.7}2{402.7}0{403.7}1{404.12}185.2{ 405.7}25{406.7}1{409.7}3{1.7}"
  9.     TArr = Split(MyStr, "}")
  10.     For i = LBound(TArr) To UBound(TArr)
  11.         Dim NewArr
  12.         TempStr = TArr(i)
  13.         If Trim(TempStr) <> "" Then
  14.             NewArr = Split(TempStr, "{")
  15.             List1.AddItem NewArr(0)
  16.         End If
  17.     Next
  18.     MsgBox "Over"
  19.  
Regards
Veena
Nov 5 '07 #11
9815402440
180 100+
Hi Priyanka

I am just suggesting the logic. I don't know what values you are expecting. I tried the file you sent, but no error was produced by the code. Because first few lines in the file cannot be used to extract values I have changed the code as follows:

Expand|Select|Wrap|Line Numbers
  1. Dim fso As New FileSystemObject
  2. Dim ts As TextStream
  3. Set ts = fso.OpenTextFile("F:\Documents and Settings\XPPRESP3\My Documents\rawdata1.txt")
  4. Dim varBFR
  5. Dim i As Integer
  6. Dim strString As String
  7. While Not ts.AtEndOfStream
  8.     strString = ts.ReadLine
  9.     If InStr(1, strString, "}", vbTextCompare) > 0 Then
  10.         varBFR = Split(strString, "}")
  11.         For i = 0 To UBound(varBFR)
  12.             Debug.Print Val(varBFR(i))
  13.         Next
  14.     End If
  15. Wend
But this does not mean that this code will give the actual result you require. This is just to explain the logic. You have to modify the code according to your requirements.

Don't test large files in the debug window. You must create a breakpoint and check each value of varBFR(i) and then decide what to do with it.

Regards,
manpreet singh dhillon hoshiarpur
Nov 5 '07 #12
Hey thanks...now I want to add that data in database... any ideas?
Nov 6 '07 #13

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

Similar topics

4
by: qwweeeit | last post by:
The standard split() can use only one delimiter. To split a text file into words you need multiple delimiters like blank, punctuation, math signs (+-*/), parenteses and so on. I didn't...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
1
by: TJ | last post by:
I am very new to C# (this is my first real project), therefore please be patient if my question is considered being to newbie. I am modifying a program which takes a text file, does some...
1
by: Krish | last post by:
I have requirement, that i get one big chunk of text file. This text file will have has information, that on finding "****End of Information****", i have to split them individual text file with our...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
3
by: edoardo.poeta | last post by:
I'm a dummy. I have a basic knowledge of javascript and I want to split a string, but I receive an error at line 15. Where my error in make the array? Why? Can someone help me to resolve? Thank's....
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
12
by: garyusenet | last post by:
string lines = File.ReadAllLines(@"c:\text\history.txt"); foreach (string s in lines) { ArrayList results = new ArrayList(); string delimit = ";"; string currentline = s.Split(";"); ...
6
by: ivan.perak | last post by:
Hello, im a beginner in VB.NET... The thing i would like to do is as it follows.... I have a text file (list of names, every name to the next line) which is about 350000 lines long. I would...
7
by: AMP | last post by:
Hello, I am trying to split a string at the newline and this doesnt work: String Channel = FileName.Split("\r"); What am I doing wrong? Thanks Mike
0
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.