我想将a拆分String为一个String[]数组,其元素符合以下条件.
s.getBytes(encoding).length不应该超过maxsize(int).
如果我用StringBuilder或+运算符连接拆分的字符串,结果应该是原始字符串.
输入字符串可以具有unicode字符,当以例如UTF-8编码时可以具有多个字节.
所需的原型如下所示.
public static String[] SplitStringByByteLength(String src,String encoding, int maxsize)
Run Code Online (Sandbox Code Playgroud)
和测试代码:
public boolean isNice(String str, String encoding, int max)
{
//boolean success=true;
StringBuilder b=new StringBuilder();
String[] splitted= SplitStringByByteLength(str,encoding,max);
for(String s: splitted)
{
if(s.getBytes(encoding).length>max)
return false;
b.append(s);
}
if(str.compareTo(b.toString()!=0)
return false;
return true;
}
Run Code Online (Sandbox Code Playgroud)
虽然输入字符串只有ASCII字符似乎很容易,但它可以共存多字节字符的事实让我感到困惑.
先感谢您.
编辑:我添加了我的代码实现.(低效)
public static String[] SplitStringByByteLength(String src,String encoding, int maxsize) throws UnsupportedEncodingException
{
ArrayList<String> splitted=new ArrayList<String>();
StringBuilder builder=new StringBuilder();
//int l=0;
int …Run Code Online (Sandbox Code Playgroud) 我目前有一个类,让我们称之为Person,使用类似的构造函数.
public class Person
{
private String name;
public Person(String name)
{
this.name = name;
System.out.println("This person is: "+getName());
}
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我们使用更具体的Person类继承该类,在本例中为Employee.
public class Employee extends Person
{
private int id;
public Employee(String name, int id)
{
super(name);
this.id = id;
System.out.println("This person is: "+getName()+", identified by #"+getId());
}
public int getId()
{
return this.name;
}
public void setId(int id)
{
this.id = id; …Run Code Online (Sandbox Code Playgroud) 我在 Android 上使用 Jetpack Compose 实现了一个简单的对话框。
我试图在 时显示警告isRehearsal消息true。
isRehearsal当用户单击按钮时,变量会被切换,并且当用户单击按钮和切换时,更改按钮效果很好isRehearal。
问题是,当 的初始值为isRehearsalisfalse并且后来变量变为时,警告文本不会出现true。isRehearsal当我将的初始值更改为 时true,文本会在isRehearsal变为false或时消失/显示正常true。
var isRehearsal by remember { mutableStateOf(false) }
Dialog(
onDismissRequest = { dismiss() },
DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true)
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.background(White, shape = RoundedCornerShape(8.dp))
.fillMaxWidth()
.padding(12.dp)
) { // the box does not resize when the caution …Run Code Online (Sandbox Code Playgroud) 我正在尝试将IL反汇编程序集成到我的反汇编应用程序(Android-Disassembler)中,但是找不到一些可以进行CIL反汇编的库。因此,我正在尝试为CIL开发一个简单的反汇编程序。所以我在互联网上搜索(堆栈溢出,谷歌,维基百科等)。但是我找不到CIL汇编代码如何变成字节码。
我在二进制编辑器中打开了一个C#应用程序(以为可以找到人类可读的IL源代码),但是我只能在其中找到一些二进制文件。
C#字节码看起来如何?
例如,X86指令字节的长度是可变的:
NOP = 0x90,
JMP = 0xEB 0xxx 0xxx 0xxx 0xxx, ...
Run Code Online (Sandbox Code Playgroud)
到目前为止,我只能找到每个指令的操作码(https://en.wikipedia.org/wiki/List_of_CIL_instructions)。但是我也想知道操作数也适用于操作码。
(如88 /r为mov,不仅是88。)
java ×2
android ×1
c# ×1
cil ×1
disassembly ×1
inheritance ×1
kotlin ×1
overriding ×1
string ×1
super ×1