小编Dys*_*ial的帖子

哪一个更快?正则表达式还是EndsWith?

什么会更快?

public String Roll()
{
    Random rnd = new Random();
    int roll = rnd.Next(1, 100000);
    if (Regex.IsMatch(roll.ToString(), @"(.)\1{1,}$"))
    {
        return "doubles";
    }
    return "none";
}
Run Code Online (Sandbox Code Playgroud)

要么

public String Roll()
{
    Random rnd = new Random();
    int roll = rnd.Next(1, 100000);
    if (roll.ToString().EndsWith("11") || roll.ToString().EndsWith("22")  || roll.ToString().EndsWith("33")  || roll.ToString().EndsWith("44")  || roll.ToString().EndsWith("55")  || roll.ToString().EndsWith("66")  || roll.ToString().EndsWith("77")  || roll.ToString().EndsWith("88")  || roll.ToString().EndsWith("99")  || roll.ToString().EndsWith("00"))
    {
        return "doubles";
    }
    return "none";
}
Run Code Online (Sandbox Code Playgroud)

我目前正在使用一个非常长的if语句列表,其中包含正则表达式,以检查int是否以双打,三元组,四元组,四元组等结尾...所以我想知道在更改所有内容之前哪一个更快.

c# regex windows string performance

26
推荐指数
3
解决办法
2925
查看次数

使用ADB在Android上粘贴文字?

这似乎是一个重复的问题,但请听我说.

我基本上需要按Android里面的"CTRL + V".我需要将当前的Android剪贴板粘贴到聚焦的TextBox中.

所以这:

adb shell input text [text]
Run Code Online (Sandbox Code Playgroud)

不会这样做,因为它要求我自己输入文本.我只需要粘贴当前的剪贴板.

这可能通过ABD吗?我用谷歌搜索和谷歌搜索,我发现的是设置剪贴板内容的方法,实际上只是按下粘贴按钮.

为了便于发展

android copy-paste adb

10
推荐指数
2
解决办法
6524
查看次数

如何更新SQLite DB中的值?

我正在尝试更新SQLite数据库中的特定行,但它似乎不起作用.这就是数据库的样子.

-----------------------
_id | user | coins
-----------------------
1   | me   | 20
-----------------------
Run Code Online (Sandbox Code Playgroud)

这就是我的代码:

public static void updateUserWallet() throws SQLException {
        try {
            int coins;
            Class.forName("org.sqlite.JDBC");
            Connection connection = DriverManager.getConnection("jdbc:sqlite:Database.db");

            String query = "Select * from userSettings WHERE user = " + "'" + lastUser + "'";
            Statement statement = connection.createStatement();
            ResultSet result = statement.executeQuery(query);

            while (result.next()) {
                coins = result.getInt("coins");
                result.updateInt("coins", 10);
                result.updateRow();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
Run Code Online (Sandbox Code Playgroud)

选择表和东西是有效的,但第二个我执行此代码,它崩溃:

result.updateInt("coins", 10);
result.updateRow();
Run Code Online (Sandbox Code Playgroud)

出现此错误:

java.sql.SQLException: …
Run Code Online (Sandbox Code Playgroud)

java sqlite jdbc

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

标签 统计

adb ×1

android ×1

c# ×1

copy-paste ×1

java ×1

jdbc ×1

performance ×1

regex ×1

sqlite ×1

string ×1

windows ×1