| | |
Need Help TXT to XML Converter
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
VB.NET Syntax (Toggle Plain Text)
Imports System.IO Imports System.Text Public Class frmReadFile Private Shared Sub TxtToXML(ByVal inFile As String, ByVal outFile As String) Dim sr As New StreamReader(inFile) Dim sb As New StringBuilder() Do While sr.Peek() >= 0 Dim line As String = sr.ReadLine() Dim fields() As String = line.Split(New [Char]() {","c}, System.StringSplitOptions.None) sb.AppendLine("<CuePoint>") sb.AppendLine(" <Time>" & fields(0).Trim() & "</Time>") sb.AppendLine(" <Type>event</Type>") sb.AppendLine(" <Name>Marker " & fields(1).Trim() & "</Name>") sb.AppendLine(" <Parameters>") sb.AppendLine(" <Parameter>") sb.AppendLine(" <Name />") sb.AppendLine(" <Value>" & fields(2).Trim() & "</Value>") sb.AppendLine(" </Parameter>") sb.AppendLine(" </Parameters>") sb.AppendLine("</CuePoint>") Loop sr.Close() sr.Dispose() Dim result As String = sb.ToString() If (File.Exists(outFile)) Then File.Delete(outFile) End If File.WriteAllText(outFile, sb.ToString()) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'This is since I don't have your file. Change this to the path on YOUR machine TxtToXML("C:\dotnetwin\example.txt", "C:\dotnetwin\example.xml") MessageBox.Show("Done") End Sub End Class
It ran in under a second. Doesn't this do what you want?
•
•
Join Date: Sep 2009
Posts: 10
Reputation:
Solved Threads: 0
Thank you so much! (had to fix one thing in script and that was switch fields 0 and 2) I was looking to find a command that did what (& fields(0).Trim() &) does.
One last thing. During the conversion is it possible to make the thing change a line such as (" <Time>" & fields(2).Trim() & "</Time>") to go from 1.3107711 to 1310 (cut off 7711 and take out decimal)? I need this done for each time value.
I know what i typed may look confusing so if need be i can clarify.
One last thing. During the conversion is it possible to make the thing change a line such as (" <Time>" & fields(2).Trim() & "</Time>") to go from 1.3107711 to 1310 (cut off 7711 and take out decimal)? I need this done for each time value.
I know what i typed may look confusing so if need be i can clarify.
Last edited by ktkevin1222; Sep 19th, 2009 at 6:03 pm.
VB.NET Syntax (Toggle Plain Text)
sb.AppendLine(" <Time>" & decimal.Parse(fields(0).Trim()).ToString("F4") & "</Time>")
•
•
Join Date: Sep 2009
Posts: 10
Reputation:
Solved Threads: 0
That is almost what Im looking for. this last part I couldn't figure out. I need to have the same format except also get rid of the decimal. It seems obvious but i can't figure it out.
Also I need to convert 52.000000 to 0, 160.000000 to 1, and 271.000000 to 2. Haven't been able to do a convert or replace command correctly.
Also I need to convert 52.000000 to 0, 160.000000 to 1, and 271.000000 to 2. Haven't been able to do a convert or replace command correctly.
Last edited by ktkevin1222; Sep 19th, 2009 at 9:47 pm.
How are you doing the math here?
0-99 = 0
100-199 = 1
200-299 = 2 ?
If so:
Results in:
0-99 = 0
100-199 = 1
200-299 = 2 ?
If so:
VB.NET Syntax (Toggle Plain Text)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim lst As New List(Of String) lst.Add("52.000000") lst.Add("160.000000") lst.Add("271.000000") For Each s In lst Dim i1 As Integer = GetInteger(Decimal.Parse(s)) Console.WriteLine("Original Value: {0}", s) Console.WriteLine("New Value: {0:F0}", i1) Next End Sub Private Shared Function GetInteger(ByVal someDecimal As Decimal) As Integer If (someDecimal <= 0) Then Return 0 End If Return Convert.ToInt32(Math.Floor(someDecimal / 100)) End Function
Results in:
text Syntax (Toggle Plain Text)
Original Value: 52.000000 New Value: 0 Original Value: 160.000000 New Value: 1 Original Value: 271.000000 New Value: 2
![]() |
Similar Threads
- Looking for API (java) to convert .doc into .pdf (Java)
- database connection (Java)
- wxWidgets - RichTextCtrl - Is ther one? (Python)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- Uploading zip files (DaniWeb Community Feedback)
- Text file to XML (XML, XSLT and XPATH)
- Great Freewares (Windows Software)
- Read XML File in C/C++ (C++)
- Store Bluetooth remote address to a text file (C++)
Other Threads in the VB.NET Forum
- Previous Thread: Help with the FormClosing() Event
- Next Thread: .Net Framework
| Thread Tools | Search this Thread |
actionscript3 ads adsense alignment api array asp.net assembly based black blogger blogging buy c# c++ code compression console createrange() delete design development dictionary edit editor error events external file flash flipbook game gdata getselection google html import javascript kernel keyboard label link linspire linus linux microsoft news node nodes openoffice optimisation parse perl php port portfolio printer programming python revenue review richtextbox rpg rss serialization soap speech split standards swappingxmlfromflash swappingxmlnodes swf tanenbaum tannenbaum technology text textbox torvalds transform txttoxmlconverter unicode unit vb2008 w3c web website win32 xml xmlnotloading xmlonserver xsl xslt







