472,139 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Strip string before # (a charc)

24
Hey Guys,

First time here, i usually resort to google (but for the first time in 3 years he (or she) cant help me) ... Im making some software that generates html reports which can be viewed within the program and they're exported with bookmark links so that when you click a link (bookmark) it adds the bookmark to the end of the address (changes the window to http://address/file.html#timmy) as this happens the program realises the address has changed so it grabs the new address and sticks it into a string ... i then want to strip that string anything before and including the #.

so in this case i want to be left with the word timmy
(in actual terms, this well be a membership number not a name but it shouldnt make any difference )

i have this, but it keeps returning nothing. Perhaps it'll give you something to work with ...

Expand|Select|Wrap|Line Numbers
  1. Public Function DeleteString( _
  2.       ByVal vString As Variant _
  3.     , Optional ByVal vStartPos As Variant _
  4.     , Optional ByVal vLength As Variant _
  5.     ) As Variant
  6.  
  7.     End Function
  8.  
  9. Public Sub addresschange()
  10. Dim address As String
  11. Dim membername As String
  12.  
  13. address = web.LocationURL
  14. findbm = "#"
  15. thename = InStr(address, findbm)
  16. membername = DeleteString(address, 1, thename)
  17.  
  18. MsgBox membername 'membername is null ??
  19.  
  20. end sub
ignore how the program recognises how the routine is called, i simply want to strip the string ... could someone put me out my misery please :)
Sep 28 '07 #1
7 1331
cugone
20
Because you did not mention what version of Visual Basic you are writing in, I'm going to assume 2005. :)

Anyway, it's a very simple process to extract a string using the String.substring and String.IndexOf methods:

Expand|Select|Wrap|Line Numbers
  1.         Dim address As String = "http://address/file.html#timmy"
  2.         Dim strMemberName As String
  3.         strMemberName = address.Substring(address.IndexOf("#") + 1)
  4.  
The substring method parameters are startIndex and length. If length is omitted the substring returned is from startIndex to the end of the string, including startIndex.

The IndexOf method returns the index of a specific character in a string. Because there can only be one octothorpe in any given URI you get the index of that specific character. Since you do not want the octothorpe included you add one to the returned index.

Hope that helps.
Sep 28 '07 #2
Killer42
8,435 Expert 8TB
i have this, but it keeps returning nothing. Perhaps it'll give you something to work with ...
Looks to me as though it's returning nothing because the DeleteString routine does nothing. Perhaps you left something out, there?

By the way, cugone, though I could be mistaken, I think the use of Variant data type probably indicates VB6. Wasn't that replaced by Object in VB.Net?
Oct 1 '07 #3
cugone
20
Looks to me as though it's returning nothing because the DeleteString routine does nothing. Perhaps you left something out, there?

By the way, cugone, though I could be mistaken, I think the use of Variant data type probably indicates VB6. Wasn't that replaced by Object in VB.Net?
Why yes, yes it was I didn't notice it because he said not to pay attention to that routine. :/ Well, code937, if you ever switch to 2005, that's how you do it.
Oct 1 '07 #4
Killer42
8,435 Expert 8TB
Why yes, yes it was I didn't notice it because he said not to pay attention to that routine. :/
First law of debugging, I think - don't believe what anyone tells you, check it out for yourself. :)
Oct 1 '07 #5
code937
24
Hey guys, I almost forgot I posted this until I went back to this part of the program and realised I still hadn't worked out how to do this. Yeah I'm using VB6 still ... I know I should update (of which I have got a copy of .Net) but I can do so much in VB6 that I wouldn't have a clue about in .Net .... anywho, I'm gunna check out that bit of code in VB6.

Cheers

--- update, no because I'm using VB6 that code doesnt work :$ --

Any chance of a lickle teeny bit more guidance?
Oct 3 '07 #6
code937
24
i hate to bump the thread but can anyone else help ? :)
Oct 6 '07 #7
Killer42
8,435 Expert 8TB
i hate to bump the thread but can anyone else help ? :)
:O How rude! ;)

Let's see, if I remember correctly (after a quick flick back through the thread), you want a VB6 routine to take something like "http://address/file.html#timmy" and return the part after the "#". Seems simple enough.

Expand|Select|Wrap|Line Numbers
  1. Public Function Version1(ByVal OriginalString As String, ByVal Delimiter As String) As String
  2.   Version1 = Split(OriginalString, Delimiter)(1)
  3. End Function
  4.  
  5. Public Function Version2(ByVal OriginalString As String, ByVal Delimiter As String) As String
  6.   Version2 = Mid$(OriginalString, InStr(1, OriginalString, Delimiter) + 1)
  7. End Function
There's two different functions that do much the same thing - take you pick.

Note that this is more or less "proof of concept" code. It doesn't take into account situations such as empty strings, no "#" in the string, and so on.
Oct 6 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Hank | last post: by
3 posts views Thread by Brian | last post: by
4 posts views Thread by beliavsky | last post: by
25 posts views Thread by electrixnow | last post: by
5 posts views Thread by Senger | last post: by
10 posts views Thread by micklee74 | last post: by
4 posts views Thread by G | last post: by
3 posts views Thread by Colin J. Williams | last post: by

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.