Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert string into String at known value vb.net

Posted on 2010-08-25
9
Medium Priority
?
434 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

972 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