小编tom*_*136的帖子

PHP字符串加入速度慢?

php处理大量字符串似乎很慢,无论如何我可以提高它的速度吗?我试图写的代码会将图像变成一串RGB值供以后使用,就像这样

$string = "255:255:253#12:12:23#33:34:24"/*an output of a $SIZE = 3 image*/
Run Code Online (Sandbox Code Playgroud)

问题是当$ SIZE大到256时,产生字符串需要1秒钟

$r = "";
$g = "";
$b = "";

for($y = 0; $y <= $SIZE-1; $y++){
    for($x = 0; $x <= $SIZE-1; $x++){


        {$r .= $arr2[$y][$x]["R"].":";}

        {$g .= $arr2[$y][$x]["G"].":";}

        {$b .= $arr2[$y][$x]["B"].":";}

    }
}
$r = rtrim($r, ":");
$g = rtrim($g, ":");
$b = rtrim($b, ":");
$str_a .= $r."#".$g."#".$b;
Run Code Online (Sandbox Code Playgroud)

php arrays string variables loops

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

Android 检查 UUID 是否有效

有没有办法检查字符串是否是有效的 UUID?

在我的情况下,我有文件列表,其中一些文件名是由 生成的 UUID UUID.randomUUID().toString(),其余的只是普通.jpg文件。

我知道通过使用UUID.fromString(filename)和捕获IllegalArgumentException抛出,我将能够检查是否filename是格式正确的 UUID。但考虑到文件列表将包含大量文件,这似乎非常昂贵。有没有一种方法可以让我在不引发异常的情况下进行检查?

uuid android

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

找不到符号Serializable?

为什么这样:

package com.example;

import com.example.Foo.Bar.Baz;

import java.io.Serializable; // I did import Serializable...

public class Foo implements Serializable {

    public final Bar bar;

    public Foo(Bar bar) {
        this.bar = bar == null ? new Bar(Baz.ONE) : bar;
    }

    public static class Bar implements Serializable { // this is line 15, where the compiler error is pointing 

        public enum Baz {
            ONE
        }

        public final Baz baz;

        public Bar(Baz baz) {
            this.baz = baz;
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

给我这个:

[ERROR] <path to file>/Foo.java:[15,44] …
Run Code Online (Sandbox Code Playgroud)

java serialization compiler-errors serializable

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

Java String.split()拆分每个字符而不是给定正则表达式

我有一个字符串,我想分成一个数组:

SEQUENCE? 1A?2B?3C

我尝试了以下正则表达式:

((.*\s)|([\x{2192}]*))

1. \x{2192} is the arrow mark
2. There is a space after the colon, I used that as a reference for matching the first part
Run Code Online (Sandbox Code Playgroud)

它适用于测试人员(OSX中的模式) 在此输入图像描述

但它将字符串拆分为:

[, , 1, A, , 2, B, , 3, C]

如何实现以下目标?:

[1A,2B,3C]

这是测试代码:

String str = "SEQUENCE? 1A?2B?3C"; //Note that there's an extra space after the colon
System.out.println(Arrays.toString(str.split("(.*\\s)|([\\x{2192}]*)")));
Run Code Online (Sandbox Code Playgroud)

java regex

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