Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. LastIndexOf("") in C#

LastIndexOf("") in C#

Scheduled Pinned Locked Moved C#
csharptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jayarajmrj
    wrote on last edited by
    #1

    My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code

    H V L 3 Replies Last reply
    0
    • J jayarajmrj

      My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code

      H Offline
      H Offline
      hamid_m
      wrote on last edited by
      #2

      you could split an string with specifics chars. name = name.Split(new char[] { ' ' })[1];

      1 Reply Last reply
      0
      • J jayarajmrj

        My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        jayarajmrj wrote:

        My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder

        I think what you need is

        string sitePath = srcUrl.SubString(iStartIndex + 1);

        Cheers, Vıkram.


        After all is said and done, much is said and little is done.

        1 Reply Last reply
        0
        • J jayarajmrj

          My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, if you need to find the last slash, a single invocation of LastIndexOf would do it, and it would need only one parameter. If you give LastIndexOf a start parameter as well, be careful it will search from that position down to index zero. And I guess you could tackle the problem with the URI class too. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups