473,387 Members | 1,512 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.

How to get string within string

I have this code in html:

<a href="domain.com">click here</a>

How can I grab the string click here or any other strings between "> and
</a>?
Nov 21 '05 #1
7 3137

August 11, 2004

You would have to add an "id" property to it. Then you can reference
it
in code.

<a href="domain.com" id="myahref">click here</a>

Then you can use the Controls collection to get the string...

Private Sub Button1_Click(...)
label1.text = myahref.Controls(0)
End Sub

If you have controls within it:

<a href="domain.com" id="myahref">click here
<asp:Textbox id="mytextbox" ... />
</a>

Then you would have to know what index the string is at in the Controls
Collection. I hope this answers your question!
Joseph MCP
"Richard Aubin" wrote:
I have this code in html:

<a href="domain.com">click here</a>

How can I grab the string click here or any other strings between "> and
</a>?

Nov 21 '05 #2
Hello Joseph,

I think what I want to do is the following.

Find the first occurence of
..com">

Count 6 characters to start the index after the >
Find the position of </a> in the string (-1 to go to the character before
the "<")

Then grab everything between Starting Position and the second position.

I'm doing this to a remote html page that I don't have access to.

"Joseph MCP" <Jo*******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...

August 11, 2004

You would have to add an "id" property to it. Then you can reference it
in code.

<a href="domain.com" id="myahref">click here</a>

Then you can use the Controls collection to get the string...

Private Sub Button1_Click(...)
label1.text = myahref.Controls(0)
End Sub

If you have controls within it:

<a href="domain.com" id="myahref">click here
<asp:Textbox id="mytextbox" ... />
</a>

Then you would have to know what index the string is at in the Controls Collection. I hope this answers your question!
Joseph MCP
"Richard Aubin" wrote:
I have this code in html:

<a href="domain.com">click here</a>

How can I grab the string click here or any other strings between "> and
</a>?

Nov 21 '05 #3
Richard,

I do not exactly know what you mean however the part you describe is the
text with mshtml.

http://msdn.microsoft.com/library/de...ng/hosting.asp

Maybe it helps?

Cor
Nov 21 '05 #4
"Richard Aubin" <rcaubin@safe-mailDOTnet> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
Hello Joseph,

I think what I want to do is the following.

Find the first occurence of
.com">


What about if it's not a .com address (such as .edu)? I'd get the position
of the first ">" and the last "<" and grab everything in between.

Nov 21 '05 #5
Richard Aubin wrote:
I have this code in html:

<a href="domain.com">click here</a>

How can I grab the string click here or any other strings between ">
and </a>?


How's this?

\\\
Dim s As String = "<a href=""domain.com"">click here</a>"
Dim startPos As Integer
Dim endPos As Integer
Dim t As String

'Get the position of the > character
startPos = InStr(s, ">")
'Get the position of the </a> characters
endPos = InStr(s, "</a>")
'Make sure both strings were found and the end pos is after the startpos
If startPos > 0 And endPos > startPos Then
'Skip over the > character itself
startPos += 1
'Extract the characters between startPos and endPos
t = Mid(s, startPos, endPos - startPos)
'Display the result
MsgBox(t)
End If
///

--

(O)enone

Nov 21 '05 #6
You need the InStr command:
i = Instr(myStr, ".com>"
newStr = mid(myStr, i + 5)
"Richard Aubin" <rcaubin@safe-mailDOTnet> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
Hello Joseph,

I think what I want to do is the following.

Find the first occurence of
.com">

Count 6 characters to start the index after the >
Find the position of </a> in the string (-1 to go to the character before
the "<")

Then grab everything between Starting Position and the second position.

I'm doing this to a remote html page that I don't have access to.

"Joseph MCP" <Jo*******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...

August 11, 2004

You would have to add an "id" property to it. Then you can

reference
it
in code.

<a href="domain.com" id="myahref">click here</a>

Then you can use the Controls collection to get the string...

Private Sub Button1_Click(...)
label1.text = myahref.Controls(0)
End Sub

If you have controls within it:

<a href="domain.com" id="myahref">click here
<asp:Textbox id="mytextbox" ... />
</a>

Then you would have to know what index the string is at in the

Controls
Collection. I hope this answers your question!
Joseph MCP
"Richard Aubin" wrote:
I have this code in html:

<a href="domain.com">click here</a>

How can I grab the string click here or any other strings between "> and </a>?


Nov 21 '05 #7
This is exactly what I needed. Thanks!

Works like a charm!

Richard.

"Oenone" <no***@nowhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Richard Aubin wrote:
I have this code in html:

<a href="domain.com">click here</a>

How can I grab the string click here or any other strings between ">
and </a>?


How's this?

\\\
Dim s As String = "<a href=""domain.com"">click here</a>"
Dim startPos As Integer
Dim endPos As Integer
Dim t As String

'Get the position of the > character
startPos = InStr(s, ">")
'Get the position of the </a> characters
endPos = InStr(s, "</a>")
'Make sure both strings were found and the end pos is after the startpos
If startPos > 0 And endPos > startPos Then
'Skip over the > character itself
startPos += 1
'Extract the characters between startPos and endPos
t = Mid(s, startPos, endPos - startPos)
'Display the result
MsgBox(t)
End If
///

--

(O)enone

Nov 21 '05 #8

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

Similar topics

0
by: Igor2004 | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
0
by: Igor Nikiforov | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
3
by: Eric Theil | last post by:
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if...
4
by: Ralph Noble | last post by:
Does anyone know of a string function in Access that will allow me to count the number of instances one string occurs within another? Or if there is some sort of word count function? If there is,...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
4
by: Mark | last post by:
OK. Here we go. I have an ASP.NET application that does many hits to a SQL Server DB on a separate server. When I first created this application (2 years ago) and was very new to ASP/ASP.NET, to...
1
by: pmelanso | last post by:
Hello, I am trying to create a method that will see if one string contains a different string: This is what I have so far: Private Function containString(ByVal string1 As String, ByVal...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
0
by: ReeceSeeSharp | last post by:
Having difficulty trying to get this code in .NET (C#) to print out this string EXACTLY as it prints out within Java using a) the MD5 hashing algorithm and B). In Java here's how a string "ididnot"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.