Solved

Insert string into String at known value vb.net

Posted on 2010-08-25
9
428 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reactjs with .NET 3 126
How to repeat the data 4 43
What is newest platform to convert a massive Windows Forms program to? 7 77
Need a quick overview of Selenium testing 2 35
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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