How to get second index of any substring in ASP.Net using VB.Net?

I have one string as-
sCurrnetURL = ""

In above URL I want that 50 i.e. port no. but it could be 100 or 200 or 1500
How could I get that number only also that virtaul directory name ie. MIS might not be same.
Currrently I used this code -
Dim sGetURL As String, sPortNoInURL As String
Dim iVal As Integer, iValOfSlash As String
      sGetURL = Request.Url.ToString
      iVal = InStr(sGetURL, ":")
      iValOfSlash = sGetURL.IndexOf("/MIS")
      If iVal > 0 Then
            sPortNoInURL = sGetURL.Substring((iVal + 1), ((iValOfSlash - iVal) - 1))
      End If

But above code has two problems - first one that in iVal it returns value of first : i.e. "http:"
so here I want want second index of 50.
Another problem is that I am taking iValOfSlash hard coded i.e. "/MIS" might not be same.

So please give me code to get that port no. from that URL string.
3/31/2007 5:45:49 AM 91979 articles. 4 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 6


you are doing it way too difficult. You could get it by changing the last If to be

If iVal > 0 Then
            iVal = sGetURL.IndexOf(":", iVal + 1)
            sPortNoInURL = sGetURL.Substring((iVal + 1), ((iValOfSlash - iVal) - 1))
End If

 But, .Net Framework has System.Uri class for dealing with these. So instead of all the previous code, you could just write: 

Dim sCurrnetURL As String = ""

Dim url As New System.Uri(sCurrnetURL)
Dim sPortNoInURL As String = url.Port
 Which saves you from dealing with substring lookup.



Teemu Keiski
Finland, EU
3/31/2007 6:57:56 AM

Similar Artilces:

Sending SMS using or using or
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

used a to converter and am now getting a syntax error.
ok I used a cool utility at to convert some to and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

How to get RS (From VB6) to .NET (VB.NET)
Hi Friends,         I have requirement, there is one function in VB6 it returns a RS, I need to call that function in  VB.NET, how to get those values into .NET, if can any body can help (pass me some code snippets), that will be greate, Thank you.Madhu... -Madhu hey guys i got this one just by using fill method.-Madhu...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

How to get new web app to use .NET 2.0 on Win2K server using .NET 1.1 as default framework?
I have .net framework1.1 and 2.0 on our server running win2K. i have existing applications that uses 1.1, i also have a new app that use 2.0.  how can i set my new .NET 2.0 app to point to 2.0 without messing up my existing .NET 1.1 apps? To specify the ASP .Net version fro a web application, do the followingIn IIS Manager select the web application -> Properties -> ASP.Net TabSelect  ASP.Net version you want to use for the applicationRegards,PrashantDont forget to click "Mark as Answer" on the post that helped you. But I am running Win2K...

how can i Get OCX File in .net IDE
hi all,      How can I generate OCX file in 2005 that will interact in web pages...?Thanks & Regards,Murthy. Hi murthysrn, As far as I know, VB 2005 and C# 2005 cannot create the project for ocx file. However, I hope the following link will be helpful to you. Creating an ActiveX Control in Visual Studio 2005,Benson YuMicrosoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other co...

use of and
i make a small website using,  in it i make a 2 class in that i want to use in that website, i dont know how to call that class. let your class is  - class clsMyClass    {        public void myFunction()        {            // do something        }    } now the first way - create objectclsMyClass myObj = new clsMyClass();myObj.myFunction(); // call function================...

converting to from offered me some sample code when I signed up with them the only problem is the sample code is in but my page that they type all of their credit card into is <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage(""); } private String readHtmlPage(string url) { ...

how to get CallerID using
Dear All!! does anyone know how to get the callerid of the incoming call using vb net or C# i have a telephone line connected with a modem, i need to answer the incoming call by getting the caller id information. Need assistance.     Hey,This forum is dedicated to which is a web based technology.As such we dont have access to this level of hardware through the browser. I am sure if anyone on here sees this post and they know the answer they will post it but you would probably get a better response if you want to the dedicated Windows Forms forums at:http://...

------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ...... vs vs
just out of curiousity which looks, acts most like java? i'm still learning trying to used to but it seems that it was easier to do some stuff with java. C# is Java++ in my opinion. If you have done C or Jave you will prefer C#.Mike Schellenberger - MCAD If you are looking for language similar to java go for J#. However most code samples you find on the net will be in VB.NET and C#....

How to use InterBase with VS.NET (
Hi all; Q1:How can I use "InterBase" as a RDMS with Visual Studio.NET (VB.NET) for developing a small application?? Q2:What should I use for a Data Provider? Q3:How ConnectionString will be build?? Thanks in advanced!Regards,CS4Ever~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Dont forget to click "Mark as Answer" on the post that helped you.This credits that member, earns you a point and marks your thread as Resolved so we will ALL know you have been helped. This will help me, you and others....

I am not getting my mail open on my net as net is running
Name: Email: rmbala91atgmaildotcom Product: Firefox Summary: I am not getting my mail open on my net as net is running Comments: My mail is not getting opening. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20100401 Firefox/3.6.3 From URL: Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

.Net 2.0 Web application using is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one web application using which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

how can i write this line using : container.dataitem ?.... in its not working
Dim container As GridView = CType(newLinkButton.NamingContainer, GridView) Dim dataValue As Object = DataBinder.Eval(container.dataitem, _ColName)   _ColName its just a string a name of the field in my database   This is Vb.Net code man what you want? You can convert any format from this link  If this post is answer of your question then don't forgot to Click Mark As Answer...

Web resources about - How to get second index of any substring in ASP.Net using VB.Net? -

Longest common substring problem - Wikipedia, the free encyclopedia
The longest common substring of the strings "ABABC", "BABCA" and "ABCBA" is string "ABC" of length 3. Other common substrings are "A", "AB", ...

Minimum substring cover problem
A major part of my thesis involves finding an algorithm to discover a good substring cover of text in order to properly syllabify said text. ...

App Store - YGO DeckMaster
Read reviews, get customer ratings, see screenshots, and learn more about YGO DeckMaster on the App Store. Download YGO DeckMaster and enjoy ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 325 ... - History - Commodore Pet Preview Oct 1978
Entry point to information about Commodore PET, CBM, 64, Advertising, History, Canada

Changement de nom - Changer son nom en raison d’une relation conjugale -
Changer Son Nom En Raison D’une Relation Conjugale Et Reprendre Son Ancien Nom 0){str=str.substring(0,str.indexOf('#');}if(str.indexOf('?')> ...

Swisscom - International Kommunizieren
"; oPW.document.write(y); oPW.document.close(); } function toggleLayer(pPageId, layerId) { el = document.getElementById(pPageId+'_lay'+layerId); ...

... -1){if(window.location.href.toString().lastIndexOf('?')> -1){param2=window.location.href.toString().substring(window.location.href.toString ...

Aegean Airlines - Contact Form
3000)this.value = this.value.substring(0,3000);" onblur="javascript:if (this.value.length> 3000)this.value = this.value.substring(0,3000);"> ...

Best Deals on Flights, Air Tickets, and Travel Offers - AirTran Airways
... flights for U.S., Mexico, and Caribbean travel on AirTran Airways. -1) break;}idx=idx+tsd [i].length;hname=oh[i];}path=location.href.substr ...

Resources last updated: 1/21/2016 12:01:53 PM