Solved

Insert string into String at known value vb.net

Posted on 2010-08-25
9
429 Views
Last Modified: 2012-05-10
Hi,
I have a very large string, containing a lot of HTML code which I need to insert a new paragraph block after the body tag.

I have a function like,  m = body(split,"<body>)

x = m(0), however it only returns the next part of the line, not the entire block of lines.
I think the split is only looking until the next vbclr.

Is there another way to find the BODY tag and insert a new line?

VB.net

Steve
0
Comment
Question by:Steven Wells
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 33528556
Look again and see if your body string contains the "ENTIRE" string you want to split.
0
 
LVL 9

Expert Comment

by:shadow77
ID: 33528719
newString = Replace(oldString, "<body>", "<body>newtext")
0
 
LVL 12

Author Comment

by:Steven Wells
ID: 33528720
My entire string is in the attachment, I am trying to split using the string

however, my firstsection is empty and so the secondsection.

Can it be done using reg expressions, or some other means?
  Dim m As Object
        m = body.Split("<body lang=""EN-US"" xml:lang=""EN-US"">")

        Dim firstsection As String = m(0)
        Dim secondsection As String = m(1)

Open in new window

EmailContent.txt
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33528753

use

split(body,"<body lang=""EN-US"" xml:lang=""EN-US"">")
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33528759
and declare

dim m() as string

m=split(body,"<body lang=""EN-US"" xml:lang=""EN-US"">")

Dim firstsection As String = m(0)
        Dim secondsection As String = m(1)
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 33528842
I do not get what you are trying to achieve.

I have achieved what "I think" you want by the below code (and debug image):


Dim body = File.ReadAllText("C:\EmailContent.txt")
Dim kjp = Regex.Split(body, "<body lang=""EN-US"" xml:lang=""EN-US"">")

Open in new window

email.png
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33528862
If you use string.split, that will also work.

BTW dont try to see value in debug mode, try to write the value of m(0) and (1) in a label control text.
0
 
LVL 9

Accepted Solution

by:
shadow77 earned 500 total points
ID: 33528875
This will insert
newtext
after your body tag.

        Dim fName As String = "C:\Users\shadow\Documents\ExpertsExchange\EmailContent.txt"
        Dim oldString As String = My.Computer.FileSystem.ReadAllText(fName)
        Dim findStr As String = "<body lang=""EN-US"" xml:lang=""EN-US"">"
        Dim newString As String = Replace(oldString, findStr, findStr + vbCrLf + "newtext")
        MsgBox(newString)

Open in new window

0
 
LVL 12

Author Closing Comment

by:Steven Wells
ID: 33528981
Great, I completely didn't think of this method.
Thanks for the quick response!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question