Solved

Insert string into String at known value vb.net

Posted on 2010-08-25
9
423 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
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33528753

use

split(body,"<body lang=""EN-US"" xml:lang=""EN-US"">")
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now