473,395 Members | 1,462 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,395 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 1384
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

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

Similar topics

8
by: Hank | last post by:
Hi, I have this problem with string.rstrip Python 2.2.3 (#42, May 30 2003, 18:12:08) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import string >>>...
3
by: Brian | last post by:
Hello - has anyone else had trouble with string.lstrip stripping too much? Here's what I get (Python 2.3.4): >>> import string >>> string.lstrip("test/one/two/a.b.c", "test/one/") 'wo/a.b.c'...
4
by: beliavsky | last post by:
The code for text in open("file.txt","r"): print text.replace("foo","bar") replaces 'foo' with 'bar' in a file, but how do I avoid changing text inside single or double quotes? For making...
0
by: Yuri Vanzine | last post by:
Saw this requested awhile ago on Matthew Reynolds's blog here: http://www.dotnet247.com/247reference/msgs/11/57944.aspx Problem: often times I deal with querystring-formatted strings w/o the...
25
by: electrixnow | last post by:
in MS VC++ Express I need to know how to get from one comma delimited text string to many strings. from this: main_string = "onE,Two,Three , fouR,five, six " to these: string1 =...
5
by: Senger | last post by:
Hello, I need separete a string in 2 blocks. For example: Which is my favourite fruit?|Orange Which is my favourite color?|Blue
10
by: micklee74 | last post by:
hi if i have a some lines like this a ) "here is first string" b ) "here is string2" c ) "here is string3" When i specify i only want to print the lines that contains "string" ie the first...
4
by: G | last post by:
Hello, Does anyone have any code handy which will take a certain part of a string and save it as an independant string? For example: "Thank you for visiting our web site. You were sent...
3
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed....
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.