标签: indexof

寻找孤独整数 - JavaScript

考虑数组 [1,2,2]

该数组包含两个唯一值:1、2

该数组包含重复值:2

孤独整数是1

如何返回孤独的整数?

javascript arrays filter indexof

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

Pl/SQL中的IndexOf功能

我想在varchar变量中查找特定字符的位置.

oracle plsql indexof

0
推荐指数
1
解决办法
9682
查看次数

当有多个特定字符时,如何使用IndexOf来选择特定字符?

当有多个特定字符时,如何使用SubString的IndexOf来选择特定字符?这是我的问题.我想采取路径"C:\ Users\Jim\AppData\Local\Temp \"并删除"Temp \"部分.只留下"C:\ Users\Jim\AppData\Local \"我用下面的代码解决了我的问题,但这假设"Temp"文件夹实际上被称为"Temp".有没有更好的办法?谢谢

if (Path.GetTempPath() != null) // Is it there?{
tempDir = Path.GetTempPath(); //Make a string out of it.
int iLastPos = tempDir.LastIndexOf(@"\");
if (Directory.Exists(tempDir) && iLastPos > tempDir.IndexOf(@"\"))
{
    // Take the position of the last "/" and subtract 4.
    // 4 is the lenghth of the word "temp".
    tempDir = tempDir.Substring(0, iLastPos - 4);
}}
Run Code Online (Sandbox Code Playgroud)

c# string substring indexof

0
推荐指数
1
解决办法
476
查看次数

搜索字符串以查看它是否包含使用jquery的数组中的值

我试图查看字符串是否包含关键字以确定它是城镇还是道路.由于不同值的数量,而不是写:

(Road.search("Way") != -1) || (Road.search("Road") != -1) || (Road.search("Ave") != -1)
Run Code Online (Sandbox Code Playgroud)

对于每个值,我想知道是否有更简单的方法?

价值观是

Cl,关闭,路,道路,博士,驱动器,Sq,广场,方式,大道,大道,花园,洛克,Ct,法院,露台

arrays search jquery indexof

0
推荐指数
1
解决办法
652
查看次数

在子串中使用.length(VB.NET)

无法弄清楚为什么这不起作用.

我试图分析一个包含"."的可变长度字符串.在里面的某个地方,然后剥去"." 和之前的所有人物.这是通过Web服务调用的.

在调试时,它可以正常工作,直到它在下面的最后一行,使用浏览器消息:"System.ArgumentOutOfRangeException:索引和长度必须引用字符串中的位置.参数名称:length"

有人有任何想法吗?

下面的Code1是从eform传递给Web服务的输入变量.

Dim CharNo As New Integer
CharNo = Code1.IndexOf(".")
MyCodebookValueStrip.o_Code1 = Code1.Substring(CharNo + 1, (Code1.Length - CharNo))
Run Code Online (Sandbox Code Playgroud)

vb.net indexof string-length

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

查找带双引号的字符串

我希望这行代码能够工作 -

int start = s.IndexOf(""_type": "Person""name": "");
Run Code Online (Sandbox Code Playgroud)

但很明显双引号搞乱了搜索...有关如何使这个工作的任何想法?

c# string indexof

0
推荐指数
1
解决办法
9447
查看次数

用java分割字符串

我有两种类型的字符串

command1|Destination-IP|DestinationPort
Command2|Destination-IP|DestinationPort|SourceIP|SourcePort|message
Run Code Online (Sandbox Code Playgroud)

我试图拆分String以获取我开始编码的变量,但不确定这是最好的方法

public String dstIp="";
    public String dstPort="";
    public String srcIp="";
    public String scrPort="";
    public String message="";
    public String command="";

int first = sentence.indexOf ("|"); 


                if (first > 0)
                {

                    int second = sentence.indexOf("|", first + 1);
                    int third = sentence.indexOf("|", second + 1);

                 command = sentence.substring(0,first);
                 dstIp=    sentence.substring(first+1,second);
                 dstPort= sentence.substring(second+1,third);
Run Code Online (Sandbox Code Playgroud)

我要继续这样吗?或者也许使用正则表达式?如果String是

command1|Destination-IP|DestinationPort
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,因为没有第三个 |

java regex string indexof

0
推荐指数
2
解决办法
147
查看次数

Java ArrayList indexOf返回-1

我的代码有一个奇怪的问题.

下面是我测试Chunk类的代码:

List<Chunk> chunks = new ArrayList<Chunk>();
chunks.add(new Chunk(1,1,1));
System.out.println(chunks.indexOf(new Vector3i(1, 1, 1)));
Run Code Online (Sandbox Code Playgroud)

这里是Chunk类的equals方法:

public boolean equals(Object object) {
    System.out.println("Test _1_");
    if (object != null && object instanceof Vector3i) {
        System.out.println("Test _2_");
        if((this.x == ((Vector3i) object).x)&&(this.y == ((Vector3i) object).y)&&(this.z == ((Vector3i) object).z)) {
            System.out.println("Test _3_");
            return true;
        }
    }
    System.out.println("Test _4_");

    return false;
}
Run Code Online (Sandbox Code Playgroud)

Vector3i:

public class Vector3i {
    public int x;
    public int y;
    public int z;


    public Vector3i(int x, int y, int z) {
        this.x = x;
        this.y …
Run Code Online (Sandbox Code Playgroud)

java equals arraylist indexof

0
推荐指数
1
解决办法
161
查看次数

求职面试测试 - 找出两个字符中第一个出现在字符串中的索引

我刚刚进行了在线访谈,并被问到一个简洁的问题.以为我会与社区分享,以及我的回答.看看你认为我的答案是否正确,如果没有 - 你会如何改进?我认为这可以让像我这样的人有相对较短的编码经验,试图迈出第一步.

注意 - 这个问题在正文中没有解释 - 必须自己弄清楚功能.什么函数的作用是返回的第一个实例char achar b特定的String s或-1,如果不是没有发现.

问题

尽可能简化下面的实现.如果您还可以提高性能作为简化的一部分,那就更好了!仅供参考:此代码超过35行和300多个令牌,但它可以写成5行和少于60个令牌.

static int func(String s, char a, char b)
{
    if (s.isEmpty()) return -1;

    char[] strArray = s.toCharArray();

    int i=0;
    int aIndex=-1;
    int bIndex=-1;
    while (aIndex==-1 && bIndex==-1 && i<strArray.length)
    {
        if (strArray[i] == a)
            aIndex=i;
        if (strArray[i] == b)
            bIndex=i;
        i++;
    }


    if (aIndex != -1)
    {
        if (bIndex == -1)
            return aIndex;
        else
            return Math.min(aIndex, bIndex);
    }
    else
    {
        if …
Run Code Online (Sandbox Code Playgroud)

java indexof

0
推荐指数
1
解决办法
2375
查看次数

消除scala中chars列表中的char

我在Scala中有这个字符列表:

val a = "(i am(a? list) of(/ chars in  )Scala)".toList
Run Code Online (Sandbox Code Playgroud)

我想找到第一个')'的位置并从列表中删除它.我怎样才能做到这一点?

我做了什么(但没有奏效):

val position = a.tail.indexOf(')')
a.drop(position)
Run Code Online (Sandbox Code Playgroud)

并尝试过a.take(position).我发现,这些方法droptake不能很好的为我所需要的.我希望该方法的工作原理如下:

input:  (i am(a? list) of(/ chars in )Scala)
output: (i am(a? list of(/ chars in )Scala)
                     ^
Run Code Online (Sandbox Code Playgroud)

string scala char indexof

0
推荐指数
1
解决办法
167
查看次数