Help with strings.

G

garth

Sample data.

"<td class=small bgcolor="E7E7E7">
Garth Was Here"

"<br><td class=small bgcolor="13B9C1">2006/03/08"



I'm looking for a two things.



1) A function to remove whitespaces. In the example data above not
only are there " " but there could be tabs and carriage returns.

2) I am also looking to strip off anything before the last ">" within
the string. I created a function that will do this for me, however for what
ever reason the InStrRev always returns 0. What I'm I doing wrong or how can
I fix this?



Public Function Clean_str(ByVal Str_in As String) As String

Dim Search As String

Dim Temp As String

Dim Temp2 As String

Dim start As Integer

Dim L As Integer



Search = "</td>"

L = Len(Search)

start = InStr(Str_in, Search, CompareMethod.Text)

Temp2 = Mid(Str_in, 1, start - 1)

Temp = Mid(Str_in, start + L)



'Find "> which is before the Date"

Search = "<br>"

start = InStr(Temp2, Search, CompareMethod.Text)

Temp2 = Mid(Temp2, 1, start - 1)



Search = ">"

start = InStrRev(Temp2, Search, CompareMethod.Text)

L = Len(Search)

Temp2 = Mid(Temp2, start + L)

Temp2 = Trim(Temp2)

Return Temp2

End Function
 
Z

zacks

Are you using VB6? If so, you are posting in the wrong newsgroup. If
you are using VB.NET, you should look into the String class and all of
the properties and method available for manipulating string values.
 
G

garth

I'm using "Microsoft Visual Basic 2005 Express Edition" I have read the Help
file included but there does not seem to be a reason why the InStrRev always
returns 0. Also there does not seem to be a Whitespace function.



Personally I find that the help file is less than helpful, I much prefer the
help file that SQL server 2000 has to find out more about function and how
they work.
 
Z

zacks

Sound like you have yet to grasp the concepts of OOP.

The InStrRev always returning 0 probably means you have your previous
Mid function coded incorrectly. Try to dump the value of Temp2 before
the InStrRev call to make sure.

You really need to start using the String class methods to manipulate
strings, the functions you are using are merely provided for backwards
compatiblilty with VB6.

For removing things like whitespace, most people use the String.Replace
method.
 
G

garth

You are right about the oop. Many moons ago when the grass was green I
programmed in C and Turbo Pascal since then I have done mostly scripting.
And I love my command prompt and winfile.exe too! <Grin>

I did find the Object.trim which does exactly what I want it to do. Also I
think that I have over come my huddles for now and the function work fine.
:)

Thanks for pointing me in the right direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top