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. String.LastIndexOf(string character, int startIndex, int count) BUG ???

String.LastIndexOf(string character, int startIndex, int count) BUG ???

Scheduled Pinned Locked Moved C#
helpquestion
6 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.
  • S Offline
    S Offline
    Stevo Z
    wrote on last edited by
    #1

    Hi, I've spent last hour of my work trying to make String.LastIndexOf(string character, int startIndex, int count) work. I know that it's friday afternoon etc... but still, Am I overworked or is it really a bug ?? just try : int GetLastPostion(string input, string character) { return input.LastIndexOf(character, 0, input.Length); } crashes, even input.LastIndexOf(character, 0, input.Length - 1); input.LastIndexOf(character, 0, input.Length - 2); crashes. wtf ???

    C C H 3 Replies Last reply
    0
    • S Stevo Z

      Hi, I've spent last hour of my work trying to make String.LastIndexOf(string character, int startIndex, int count) work. I know that it's friday afternoon etc... but still, Am I overworked or is it really a bug ?? just try : int GetLastPostion(string input, string character) { return input.LastIndexOf(character, 0, input.Length); } crashes, even input.LastIndexOf(character, 0, input.Length - 1); input.LastIndexOf(character, 0, input.Length - 2); crashes. wtf ???

      C Offline
      C Offline
      codemagus
      wrote on last edited by
      #2

      It just crashes? .. or is it giving you an error?

      S 1 Reply Last reply
      0
      • C codemagus

        It just crashes? .. or is it giving you an error?

        S Offline
        S Offline
        Stevo Z
        wrote on last edited by
        #3

        ArgumentutOfRangeException: Count must be positive and count must refer to a location within the string/array/collection. Parameter name: count :mad:

        C 1 Reply Last reply
        0
        • S Stevo Z

          ArgumentutOfRangeException: Count must be positive and count must refer to a location within the string/array/collection. Parameter name: count :mad:

          C Offline
          C Offline
          codemagus
          wrote on last edited by
          #4

          Just one more question: Is it this call that is actually crashing or is it possible that this is returning a -1 (because string is not found) to a function where -1 is out of range? EDIT: From MSDN: ArgumentOutOfRangeException: count or startIndex is negative. -or- startIndex minus count specify a position that is not within this instance.

          1 Reply Last reply
          0
          • S Stevo Z

            Hi, I've spent last hour of my work trying to make String.LastIndexOf(string character, int startIndex, int count) work. I know that it's friday afternoon etc... but still, Am I overworked or is it really a bug ?? just try : int GetLastPostion(string input, string character) { return input.LastIndexOf(character, 0, input.Length); } crashes, even input.LastIndexOf(character, 0, input.Length - 1); input.LastIndexOf(character, 0, input.Length - 2); crashes. wtf ???

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            This is correct. You are asking it to start searching from the start of the string, but the method works from the end of the string. It has nothing to search for.


            Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... * Reading: Developer Day 5 Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            1 Reply Last reply
            0
            • S Stevo Z

              Hi, I've spent last hour of my work trying to make String.LastIndexOf(string character, int startIndex, int count) work. I know that it's friday afternoon etc... but still, Am I overworked or is it really a bug ?? just try : int GetLastPostion(string input, string character) { return input.LastIndexOf(character, 0, input.Length); } crashes, even input.LastIndexOf(character, 0, input.Length - 1); input.LastIndexOf(character, 0, input.Length - 2); crashes. wtf ???

              H Offline
              H Offline
              Hesham Yassin
              wrote on last edited by
              #6

              I think you mean that reading this line, give you an exception :"CrossThread...." if this what u mean, u need to invoke the thread : if(textBox.InvokeRequired) { textBox.Invoke(method); }:-D

              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