473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Substract part of the string based on tags (c#)

Jay
Hi y'all,
I have a beginner question... I want to get the all the values inside of
two tags in a string.
for example:
string HTMLContent = "<b>this is a test</b> <!-- start --> Hello world <!--
End --> <i>anohter test</i> " ;

I want to get whatever is inside of the start and end tags:

string NewString = " Hello Word";

I will really apreciate any help. Thanks ahead,

Jay
Jul 21 '05 #1
3 4180
Dim st As String = "<b>this is a test</b> <!-- start --> Hello world <!-- >
End --> <i>anohter test</i> "
Dim r AS String
Dim intL As Integer = Len(st)
Dim intN, intP as Integer
If intL>0 Then
intN=Instr(0, "<!-- start --> ", st)
If intN >0 Then
Do While intP < intL
v= mid(IntP,1,st)
If v="<" then
Exit Do
End If
r=r & v
Loop
End If
End If


"Jay" <Ja*@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
Hi y'all,
I have a beginner question... I want to get the all the values inside of
two tags in a string.
for example:
string HTMLContent = "<b>this is a test</b> <!-- start --> Hello world <!-- End --> <i>anohter test</i> " ;

I want to get whatever is inside of the start and end tags:

string NewString = " Hello Word";

I will really apreciate any help. Thanks ahead,

Jay

Jul 21 '05 #2
Jay
Thanks Doug,
Do you happen to have a c# version of this code?..if not, thats ok!
Again, thanks so much for the help.
~Jay

"Doug Versch" wrote:
Dim st As String = "<b>this is a test</b> <!-- start --> Hello world <!-- >
End --> <i>anohter test</i> "
Dim r AS String
Dim intL As Integer = Len(st)
Dim intN, intP as Integer
If intL>0 Then
intN=Instr(0, "<!-- start --> ", st)
If intN >0 Then
Do While intP < intL
v= mid(IntP,1,st)
If v="<" then
Exit Do
End If
r=r & v
Loop
End If
End If


"Jay" <Ja*@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
Hi y'all,
I have a beginner question... I want to get the all the values inside of
two tags in a string.
for example:
string HTMLContent = "<b>this is a test</b> <!-- start --> Hello world

<!--
End --> <i>anohter test</i> " ;

I want to get whatever is inside of the start and end tags:

string NewString = " Hello Word";

I will really apreciate any help. Thanks ahead,

Jay


Jul 21 '05 #3
Jay <Ja*@discussions.microsoft.com> wrote:
Thanks Doug,
Do you happen to have a c# version of this code?..if not, thats ok!


Doug's code won't actually work. (It doesn't even compile without
modification, and needs further modification to work.)

I suggest you have a look at the answers to the same question you
posted a few days ago. Otherwise:

(with x as the string in question)

int startIndex = x.IndexOf ("<!-- start -->");
if (startIndex != -1)
{
int textStart = startIndex+14;
int endIndex = x.IndexOf("<!-- end -->", textStart);
if (endIndex != -1)
{
string result = x.Substring (startIndex, endIndex-startIndex);
}
else
{
// Whatever you want to do with no end tag
}
}
else
{
// Whatever you want to do with no start tag
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Hon Seng Phuah | last post by:
Hi all, I have a problem and have someone can help me. I want to substract a numerica from a string. For example: A string is: $line = RVW-30 {
2
by: Jay | last post by:
Hi y'all, I have a beginner question in c#. I need to take part of a text, based on tags. for example: string test = "blah blah<!--start -->1 2 3 4<!--end--> blah blah"; I want to get...
2
by: Got2Go | last post by:
Hello, I am trying to come up with a function that will search the source of the page for a specific string. If that string is found, then have it modify specific tags inside of a table and...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
3
by: Jay | last post by:
Hi y'all, I have a beginner question... I want to get the all the values inside of two tags in a string. for example: string HTMLContent = "<b>this is a test</b> <!-- start --> Hello world <!--...
1
by: Juan R. | last post by:
The initial CanonMath program presented here http://canonicalscience.blogspot.com/2006/02/choosing-notationsyntax-for-canonmath.html] was discussed with several specialists, including father of...
9
by: valy | last post by:
hi all, how to open two images and then substract both together to get the different? the image will be a grayscale image. A sequence of image is stored in a folder. I want to open two images and...
9
by: Francois Grieu | last post by:
Is it OK to substract two pointer-to-void ? Are they guaranteed to act as pointer-to-char ? I fail to find that discussed in ISO/IEC 9899:1999. In other words (hopefully), is the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.