Array.IndexOf - 不工作 [英] Array.IndexOf - not working
问题描述
此语句返回-1,表示未找到:
Find1 = Array.IndexOf(FilesArray," sa001")
但是该数组中特定项目的IndexOf返回值26:
Find1 = FilesArray(2).IndexOf(" sa001")
这显示值sa001。可以在FilesArray中找到。
为什么Array.IndexOf没有返回数字的任何建议(
项目的值具有该值)?
谢谢,
Al
This statement returns a -1, indicating "not found":
Find1 = Array.IndexOf(FilesArray, "sa001")
But IndexOf on a specific item in that array returns a value of 26:
Find1 = FilesArray(2).IndexOf("sa001")
This shows the value "sa001" is found in FilesArray.
Any suggestions why Array.IndexOf does not return a number (index of
item that has the value)?
Thanks,
Al
推荐答案
Al,
你确定吗,这给了我1
\\\
Dim filesarray()As String = {" ; sa000"," sa001"," sa002"}
Dim Find1 As Integer = Array.IndexOf(filesarray," sa001")
///
我希望这会有所帮助,
Cor
Al,
Are you sure of that, this gives for me 1
\\\
Dim filesarray() As String = {"sa000", "sa001", "sa002"}
Dim Find1 As Integer = Array.IndexOf(filesarray, "sa001")
///
I hope this helps,
Cor
亲爱的Al,>
只是一个确认。数组是FilesArray吗?多维度?
似乎是这样。
该文件说返回第一次出现的索引
的值在*一维*数组中或在数组的一部分中。
2005年6月1日19:42:46 -0700
Al <人********** @ hotmail.com>写道:
Dear Al,
Just a confirmation. Is the array "FilesArray" multi dimension?
It seems so.
The document said "Returns the index of the first occurrence
of a value in a *one-dimensional* Array or in a portion of
the Array. "
On 1 Jun 2005 19:42:46 -0700
"Al" <al**********@hotmail.com> wrote:
此语句返回-1,表示未找到:
Find1 = Array.IndexOf(FilesArray," sa001")<但是,该数组中特定项目的IndexOf返回值26:
Find1 = FilesArray(2).IndexOf(" sa001")
这显示值 SA001"在FilesArray中找到。
任何建议为什么Array.IndexOf不返回数字(具有该值的项目的索引)?
谢谢,
Al
This statement returns a -1, indicating "not found":
Find1 = Array.IndexOf(FilesArray, "sa001")
But IndexOf on a specific item in that array returns a value of 26:
Find1 = FilesArray(2).IndexOf("sa001")
This shows the value "sa001" is found in FilesArray.
Any suggestions why Array.IndexOf does not return a number (index of
item that has the value)?
Thanks,
Al
---
MVP kaok = MVP.ChangeMvpCategory(for C#2004-2005。);
kaok.Web =" http://www.antoine.st/" ;;
---
MVP kaok = MVP.ChangeMvpCategory("for C# 2004-2005.");
kaok.Web = "http://www.antoine.st/";
感谢您的回复。
数组是一个维度:
Public FilesArray()As String
应用程序需要搜索文件名中的单词。
我这样做:
FilesArray = Directory.GetFiles(sFolder)
所有项目都是唯一的,因为它们是文件带路径的名称(例如
" C:\ imageProject \ sa002.tif")
然后我使用For-Next循环查看每个数组中的项目
IndexOf:
Find1 = FilesArray(Fi).IndexOf(word)
这样工作正常,但阵列较大,我以为Array.IndexOf哇ld是
更快。
Cor,你提供的简单例子就是在字符串开头的
字处查看单词。我想知道这是否需要
Array.IndexOf。但是我做了一个测试,搜索了C:\,但它仍然带着-1返回
。
它只是出现了数组.IndexOf由于某种原因在
FilesArray上无效。我会用简单的例子来测试;也许它会打开一个
灯。
我有Windows XP家庭版。
考虑什么应用需求,有更好的方法吗?
Al
Thanks for your replies.
The array is one dimension:
Public FilesArray() As String
The application needs to search for words in file names.
I do this:
FilesArray = Directory.GetFiles(sFolder)
All items are unique, since they are file names with path (e.g.
"C:\imageProject\sa002.tif")
I then use a For-Next loop looking at each item in the array with
IndexOf:
Find1 = FilesArray(Fi).IndexOf(word)
This works OK but with larger array, I thought Array.IndexOf would be
faster.
Cor, the simple example you provided is looking at the word at the
beginning of the string. I had wondered if that was needed for
Array.IndexOf. But I did a test, searching for "C:\", but it still
returned with -1.
It just appears that Array.IndexOf is not working for some reason on
FilesArray. I''ll test with the simple example; perhaps it will turn a
light on.
I have Windows XP home edition.
Considering what the app needs, are there better ways to do this?
Al
这篇关于Array.IndexOf - 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!