Solved

Insert string into String at known value vb.net

Posted on 2010-08-25
9
427 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
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 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