-1

XML FILE
this is example file, there is 2 group
(real file has more than 1000 group)

 <Text>You guys were the ones calling
    out and making a racket.</Text>
  
 <Text>I thought you needed help,</Text>

i want them like this in vb
if more than 2 group it will be create new textbox automatically for every group

[textbox1]
You guys were the ones calling
out and making a racket.

[textbox2]
I thought you needed help,

can someone guide me? i think i have to find text by <Text*> tag
and split them but it's duplicated tag i can't define them

UPDATE
i use this code and it's working fine
now i can split any group i want

Dim xml = XDocument.Load("C:\Users\Administrator\Desktop\12.xml")

Dim xstr As String = xml.ToString
Dim String1 As String = "<Text>"
Dim String2 As String = "</Text>"
Dim xlist As New List(Of String)
Do
    xstr = Mid(xstr, InStr(xstr.ToLower, String1.ToLower) + String1.Length)
    xlist.Add(Mid(xstr, 1, InStr(xstr.ToLower, String2.ToLower) - 1))
    xstr = Mid(xstr, InStr(xstr.ToLower, String2.ToLower) + String2.Length)
Loop Until InStr(xstr.ToLower, String1.ToLower) = 0

Dim i = 0

Do
    RichTextBox1.Text &= xlist(i) & Environment.NewLine
    i += 1
Loop Until i = xlist.Count
DREAM
  • 352
  • 1
  • 11
  • Stackoverlfow is not a programming service, try writing some code and get back to us. You could easily get started by googling vb.net xml loop – Kevin Aug 25 '20 at 18:33
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Aug 25 '20 at 18:36
  • Note that questions that ask ["Give me a regex that does X"](https://meta.stackoverflow.com/q/285733) with no attempt are off topic on Stack Overflow. – Wiktor Stribiżew Aug 25 '20 at 18:36
  • IMHO - this isn't a regex problem but an XML one. – dbasnett Aug 25 '20 at 18:38
  • @Kevin i like to ask before search sorry // thank you guys i just update toppic – DREAM Aug 25 '20 at 18:50

1 Answers1

2

If it is XML then use XML. Here I've used XElement, LINQ, and XML literals. Hope you get some ideas from this.

    Dim xe As XElement
    'for production
    'xe = XElement.Load("put path here")

    'for test
    xe = <Subtitles>
             <Subtitle>
                 <Number>1</Number>
                 <Start>00:00:00,000</Start>
                 <End>00:00:02,236</End>
                 <Duration>2,236</Duration>
                 <Text>You guys were the ones calling
out and making a racket.</Text>
             </Subtitle>
             <Subtitle>
                 <Number>2</Number>
                 <Start>00:00:02,238</Start>
                 <End>00:00:03,343</End>
                 <Duration>1,105</Duration>
                 <Text>I thought you needed help,</Text>
             </Subtitle>
         </Subtitles>

    RichTextBox1.Text = (From el In xe...<Number>
                          Where el.Value = "1").FirstOrDefault.Parent.<Text>.Value

    ''or for 2

    'RichTextBox1.Text = (From el In xe...<Number>
    '                      Where el.Value = "2").FirstOrDefault.Parent.<Text>.Value

    RichTextBox1.Clear()
    Dim groups As IEnumerable(Of XElement)
    groups = xe...<Subtitle>

    For Each g As XElement In groups
        Dim s As String
        s = String.Format("Num. {0} Start:{1} End:{2}",
                            g.<Number>.Value,
                            g.<Start>.Value,
                            g.<End>.Value)
        RichTextBox1.AppendText(s)
        RichTextBox1.AppendText(ControlChars.Cr)
    Next
dbasnett
  • 10,010
  • 2
  • 22
  • 32