标签: indexof

在二维数组中找到元素的位置?

这里简单的问题(也许不是一个简单的答案?)

说我有一个二维数组

[0] [1] [2]
[3] [4] [5]
[6] [7] [8]
Run Code Online (Sandbox Code Playgroud)

现在假设我想获得数字6的位置

我知道使用一维数组我可以使用Array.indexOf()但是我的选择是什么?二维数组?

谢谢!

c# vb.net arrays indexof multidimensional-array

7
推荐指数
1
解决办法
4万
查看次数

DART:实例列表中的indexOf()

如何获取列表中一个实例的索引?

class Points {
  int x, y;
  Point(this.x, this.y);
}

void main() {
  var pts = new List();
  int Lx;
  int Ly;

  Points pt = new Points(25,55); // new instance
  pts.add(pt);

  int index = pts.indexOf(25); // Problem !!! How to obtain the index in a list of instances ?
  if (index != -1 ){
  Lx = lp1.elementAt(index).x;
  Ly = lp1.elementAt(index).y;
  print('X=$Lx Y=$Ly');
}
Run Code Online (Sandbox Code Playgroud)

list indexof dart

7
推荐指数
1
解决办法
1306
查看次数

wordpress .htaccess中的文件夹索引

当我在我的导航器中使用以下URL" http://www.tuto3d.netai.net/wordpress/ "时,我通常会访问我的wordpress网站,但是当我使用 http://www.tuto3d.netai.net/时,我得到了而不是文件夹的索引和wordpress文件夹的链接.我想将我的.htaccess http://www.tuto3d.netai.net/重定向到" http://www.tuto3d.netai.net/wordpress/ "

这是我的.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

# END WordPress
Run Code Online (Sandbox Code Playgroud)

先感谢您

wordpress .htaccess redirect indexof

6
推荐指数
1
解决办法
193
查看次数

string.IndexOf搜索整个单词匹配

我正在寻找一种方法来搜索字符串以获得完全匹配或完整的单词匹配. RegEx.Match并且RegEx.IsMatch似乎没有让我在哪里,我想.
请考虑以下情形:

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "SUBTOTAL 34.37 TAX TOTAL 37.43";
            int indx = str.IndexOf("TOTAL");
            string amount = str.Substring(indx + "TOTAL".Length, 10);
            string strAmount = Regex.Replace(amount, "[^.0-9]", "");

            Console.WriteLine(strAmount);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面代码的输出是:

// 34.37
// Press any key to continue...
Run Code Online (Sandbox Code Playgroud)

问题是,我不想SUBTOTAL的,但IndexOf发现这个词第一次出现TOTAL是在SUBTOTAL然后得到34.37的不正确的值.

所以问题是,有没有办法强制IndexOf只找到一个完全匹配或是否有另一种方法来强制完全匹配的单词,以便我可以找到该完全匹配的索引,然后用它执行一些有用的功能.RegEx.IsMatch并且RegEx.Match是,据我所知道的,只是boolean搜索.在这种情况下,仅知道存在完全匹配是不够的.我需要知道它在字符串中的位置.

任何意见,将不胜感激.

c# regex string substring indexof

6
推荐指数
2
解决办法
6387
查看次数

为什么Scala的indexOf(在List等中)返回Int而不是Option [Int]?

我想编写非常好看的惯用Scala代码,list indexOf foo getOrElse Int.MaxValue但现在我必须满足于寻找愚蠢的Java代码val result = list indexOf foo; if (result < 0) Int.MaxValue else result.是否有充分的理由indexOf在Scala中返回Int而不是Option[Int]

scala api-design indexof standard-library scala-collections

6
推荐指数
2
解决办法
1879
查看次数

Swift无法使用类型为"([Score],Score)"的参数列表调用"find",其中Score为结构

虽然find(["a", "b"], "c")没有问题,但在尝试查找结构数组中的结构索引时出错:

struct Score
{
    //...
}

var scores: [Score] = //...
var score: Score = //...

find(self.scores, score) // Error: Cannot invoke 'find' with an argument list of type '([Score], Score)'
Run Code Online (Sandbox Code Playgroud)

我可能是一个问题,结构默认情况下无法相互比较.但改变Scores定义class 给我同样的错误.

arrays find indexof swift

6
推荐指数
2
解决办法
7074
查看次数

我的函数返回一个包含单个整数的列表,如何让它只返回整数?

如何在保持函数单行代码的同时从结果中删除括号?

day_list = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

def day_to_number(inp):
    return [day for day in range(len(day_list)) if day_list[day] == inp]

print day_to_number("Sunday")
print day_to_number("Monday")
print day_to_number("Tuesday")
print day_to_number("Wednesday")
print day_to_number("Thursday")
print day_to_number("Friday")
print day_to_number("Saturday")
Run Code Online (Sandbox Code Playgroud)

输出:

[0]
[1]
[2]
[3]
[4]
[5]
[6]
Run Code Online (Sandbox Code Playgroud)

python list-comprehension list indexof

6
推荐指数
2
解决办法
241
查看次数

在字节数组中查找字节序列

我有一个字节数组,希望找到一些字节的"出现".

例如,00 69 73 6F 6D在一个非常大的字节数组(> 50/100兆字节)

要么

更好的反向操作:在不知道代码的情况下搜索最常见的模式,代码应该能够从文件中读取并找到它.

c# indexof

6
推荐指数
1
解决办法
2139
查看次数

IndexError:无法将“int”放入索引大小的整数中

所以我试图让我的程序从文本文件中打印出每个单词和标点符号的索引(当它出现时)。我已经完成了那部分。- 但问题是当我尝试使用这些索引位置重新创建带有标点符号的原始文本时。这是我的代码:

with open('newfiles.txt') as f:
    s = f.read()
import re
#Splitting string into a list using regex and a capturing group:
matches = [x.strip() for x in re.split("([a-zA-Z]+)", s) if x not in ['',' ']]
print (matches)
d = {} 
i = 1
list_with_positions = []
# the dictionary entries:
for match in matches:
    if match not in d.keys():
        d[match] = i
        i+=1
    list_with_positions.append(d[match])

print (list_with_positions)
file = open("newfiletwo.txt","w")
file.write (''.join(str(e) for e in list_with_positions))
file.close()
file = open("newfilethree.txt","w") …
Run Code Online (Sandbox Code Playgroud)

python runtime-error list append indexof

6
推荐指数
1
解决办法
2万
查看次数

有没有像“firstIndexOf”这样的代码?

String xStr = "hello/master/yoda";
String remv_last = xStr.substring(0, xStr.lastIndexOf("/"))
System.out.println(remv_last);
Run Code Online (Sandbox Code Playgroud)

输出

hello/master
Run Code Online (Sandbox Code Playgroud)

我的问题是;我怎样才能得到这个输出,谢谢你的帮助。

master/yoda
Run Code Online (Sandbox Code Playgroud)

string indexof

6
推荐指数
1
解决办法
8424
查看次数