473,809 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String LastIndexOf bug ?

Hi,

string s = "aXXa";
Console.WriteLi ne(s.LastIndexO f("XX",0));
Console.WriteLi ne(s.LastIndexO f("XX"));
Console.WriteLi ne(s.IndexOf("X X",0));
Console.WriteLi ne(s.IndexOf("X X"));

Result:
-1 (LastIndexOf must also return 1, but gives -1) Is it a bug ?
1 - ok
1 - ok
1 - ok

In documentation it says:
Reports the index position of the last occurrence of a specified String
within this instance. The search starts at a specified character position.
Oct 1 '05 #1
2 3541
No it's not a bug: The LastIndexOf() search works backwards from the
position specified. Hence there is no match for XX from 0.

"Ivar" <iv*@lumisoft.e e> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,

string s = "aXXa";
Console.WriteLi ne(s.LastIndexO f("XX",0));
Console.WriteLi ne(s.LastIndexO f("XX"));
Console.WriteLi ne(s.IndexOf("X X",0));
Console.WriteLi ne(s.IndexOf("X X"));

Result:
-1 (LastIndexOf must also return 1, but gives -1) Is it a bug ?
1 - ok
1 - ok
1 - ok

In documentation it says:
Reports the index position of the last occurrence of a specified String
within this instance. The search starts at a specified character position.

Oct 1 '05 #2
The search begins at the startIndex character position of this instance and
precedes backwards towards the beginning until either value is found or the
first character position has been examined.
Yes I see now.

"Siva M" <sh******@onlin e.excite.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. No it's not a bug: The LastIndexOf() search works backwards from the
position specified. Hence there is no match for XX from 0.

"Ivar" <iv*@lumisoft.e e> wrote in message
news:O%******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,

string s = "aXXa";
Console.WriteLi ne(s.LastIndexO f("XX",0));
Console.WriteLi ne(s.LastIndexO f("XX"));
Console.WriteLi ne(s.IndexOf("X X",0));
Console.WriteLi ne(s.IndexOf("X X"));

Result:
-1 (LastIndexOf must also return 1, but gives -1) Is it a bug ?
1 - ok
1 - ok
1 - ok

In documentation it says:
Reports the index position of the last occurrence of a specified String
within this instance. The search starts at a specified character position.

Oct 1 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
16367
by: Matt | last post by:
In test() method: var path="C:\test\hello.txt"; //returns -1 for path.lastIndexOf("\\"). why?? var pos=path.lastIndexOf("\\"); //return -1 But in showFile() method: We are able to get the filename. The only difference is test() hardcode the path, but in showFile() we gets the path from the file dialog.
11
1548
by: ALI-R | last post by:
why c# function for string manupolation is not as strong as other languages ,for extracting a substring from a middle of another string ,I have a lot of problems. Any suggestion or I am in the wrong spot. Thanks
3
2306
by: Brian Shannon | last post by:
Is there a VB.NET function to find the right most characters of a string similiar to Microsoft.VisualBasic.Right? I am currently using the below code to find the right most characters and am wondering if there is a more efficient or better way to do the same. dim x as string dime y as string dim lastIndexof as stirng x = New StringBuilder(WhereFunction)y = x.Length
4
1697
by: Keith Kowalski | last post by:
I am passing in a string of varied length Example1: mil2345_23.lst Example2: mil23456_1.lst Example3: mil5567_1234.lst What I need is to parse out all text after the _ (underscore) and before the ..) From example 1 I need "23" returned From example2 I need "1" Returned From Example3 I need "12345" returned
9
3472
by: koorb | last post by:
I am trying to read a line from a text file and store it in a DateTime veritable. Below is a cut down version of my problem code (in my actual version I am using a try and catch, and I am receiving each line in a loop to store into the Array) If I write the string directly into the array it works, but when I use the line from the file it doesn't go into the DateTime veriable and I get an error. Is there something I am missing? Dim...
2
256
by: Ivar | last post by:
Hi, string s = "aXXa"; Console.WriteLine(s.LastIndexOf("XX",0)); Console.WriteLine(s.LastIndexOf("XX")); Console.WriteLine(s.IndexOf("XX",0)); Console.WriteLine(s.IndexOf("XX")); Result: -1 (LastIndexOf must also return 1, but gives -1) Is it a bug ?
15
16358
by: Daren | last post by:
Hi, I need to be able to split large string variables into an array of lines, each line can be no longer than 70 chars. The string variables are text, so I would additionally like the lines to end at the end of a word, if you catch my drift. For example, I have a large string variable containing the text: "I've seen things you people wouldn't believe. Attack ships on fire
9
11983
by: senfo | last post by:
I realize it's Friday and I'm probably already on vacation for the remainder of the day; but, I have a really, really stupid question. Is there a bug in the .NET 2.0 Framework in regards to the LastIndexOf() method or am I just not understanding something that should be obvious? string myString = "This is a test"; int index = myString.LastIndexOf(' ', 0, 6); The second line throws an ArgumentOutOfRangeException exception, which says,...
3
3758
by: Mathias Weyel | last post by:
Hi Group! I encounter a strange behaviour of String.LastIndexOf when specifying start and count values. The following works: string tempString = orgString.SubString(0, mycount); int index = tempString.LastIndexOf(mychar);
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10643
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10391
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.