我使用下面的代码将用 Winword 制作的 UTF8 文件读入 Tmemo(尝试了所有 2 种方法)。该文件包含 IPA 发音字符。对于这些字符,我只看到正方形。我尝试了不同版本的 tmemo.font.charset,但没有帮助。
我能做些什么?
彼得
// OD is an TOpenDialog
procedure TForm1.Load1Click(Sender: TObject);
{
var fileH: textFile;
newLine: RawByteString;
begin
if od.execute (self.Handle) then begin
assignFile(fileH,od.filename);
reset(fileH);
while not eof(fileH) do begin
readln(fileH,newLine);
Memo1.lines.Add(UTF8toString(newLine));
end;
closeFile(fileH);
end;
end;
}
var
FileStream: tFileStream;
Preamble: TBytes;
memStream: TMemoryStream;
begin
if od.Execute then
begin
FileStream := TFileStream.Create(od.FileName,fmOpenRead or fmShareDenyWrite);
MemStream := TMemoryStream.Create;
Preamble := TEncoding.UTF8.GetPreamble;
memStream.Write(Preamble[0],length(Preamble));
memStream.CopyFrom(FileStream,FileStream.Size);
memStream.Seek(0,soFromBeginning);
memo1.Lines.LoadFromStream(memStream);
showmessage(SysErrorMessage(GetLastError));
FileStream.Free;
memStream.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我的行中有不需要的字符备忘录,我想将它们全部删除.这是我的代码:
var
del: Integer;
begin
for del := 0 to m0.Lines.Count - 1 do
begin
if (AnsiContainsStr(m0.Lines[del], 'remove me')) then
begin
m0.Lines.Delete(del);
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
上面的代码仍然留下了一些我想删除的行.它只删除其中一些.所以我尝试了另一种方法,这是做的工作.
var
i, r, n: Integer;
begin
for i := 0 to m0.Lines.Count - 1 do
begin
if (AnsiContainsStr(m0.Lines[i], 'remove me')) then
begin
for r := 0 to m0.Lines.Count - 1 do
begin
if (AnsiContainsStr(m0.Lines[r], 'remove me')) then
begin
for n := 0 to m0.Lines.Count - 1 do
begin
if (AnsiContainsStr(m0.Lines[n], 'remove me')) then
begin …Run Code Online (Sandbox Code Playgroud) 我正在使用AssertJ进行测试,并且注意到有一种检查a List<T>是否排序的方法:
public static <T> void sorted(final List<T> actual) {
try {
assertThat(actual).isSorted();
} catch (AssertionError e) {
LOGGER.error(e.getMessage(), e);
throw e;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法检查列表是否按降序排列?
我知道番石榴提供了,Ordering.natural().reverse().isOrdered(values)但是我想利用AssertJ的assert消息,因为它确实对调试很有帮助,例如
group is not sorted because element 5:
<"4000366190001391">
is not less or equal than element 6:
<"4000206280001394">
group was:
<["4000206280001363",
"4000206280001364",
"4000206280001365",
"4000206280001373",
"4000206280001388",
"4000366190001391",
"4000206280001394",
"4000366190001401",
"4000206280001403",
"4000206280001405",
....]>
Run Code Online (Sandbox Code Playgroud) 我想知道这两种情况之间的差异是什么:
class Cell
{
Messages msg;
public void getMessage()
{
msg.getMessage();
}
}
Run Code Online (Sandbox Code Playgroud)
和:
class Cell
{
Messages msg = new Messages();
public void getMessage()
{
msg.getMessage();
}
}
Run Code Online (Sandbox Code Playgroud)
我知道在第一个例子中我只声明了字段,而在第二个例子中我声明了字段,对象和指定对象到字段.但是在这两种情况下我都可以.getMessage()在Cell课堂上使用方法,那么什么是差异?我应该使用什么?
我有A类,它依赖于B类.B类再次依赖C类.结构如下:
Class A(){
@Autowired
private B b;
public void someMethod(){
b.callAnotherMethodAndGetValue();
}
}
Class B(){
@Autowired
private C c;
public void callAnotherMethodAndGetValue(){
c.callAnother();
}
}
Class ATest(){
@Spy
private B b;
public void someMethod(){
// it goes into this method, and throws null pointer exception at
// c.callAnother(); as c is null.
b.callAnotherMethodAndGetValue();
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以让堆栈c.callAnother从Test Cases 流出来.没有做的时候b.callAnotherMethodAndGetValue();
我是 Java 的新手。我现在正在学习 WeakReference 的概念。我遇到了一个可能看起来很愚蠢的问题,但我只是想找出原因。问题是:根据 Java 文档,“弱引用对象,它不会阻止其所指对象被终结、终结和回收。”
所以我做了这个小测试:
import java.lang.ref.WeakReference;
public class A {
public static void main(String[] args) {
A a = new A();
WeakReference<A> wr = new WeakReference<>(a);
a = null;
A a1 = wr.get();
System.out.println(a);
System.out.println(a1);
try {
System.gc();
Thread.sleep(10000);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(a1);
}
@Override
protected void finalize( ) {
System.out.println(Thread.currentThread().getName() + ": See ya, nerds!");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我注意到在 GC 运行后,wr.get()仍然可以返回我期望为 null 的对象,并且finalize()没有调用该方法。那么出了什么问题呢?提前感谢您的帮助!:)
我正在尝试计算两个小时之间的差异。时间格式必须是 hh:mm:ss!我实现了这个代码:
public static String timeDifference(long timeDifference1) {
long timeDifference = timeDifference1 / 1000;
int h = (int) (timeDifference / (3600));
int m = (int) ((timeDifference - (h * 3600)) / 60);
int s = (int) (timeDifference - (h * 3600) - m * 60);
return String.format("%02d:%02d:%02d", h, m, s);
}
public static void main(String[] args) throws ParseException {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String timeStart = sc.next();
String timeStop = sc.next();
char lol[]=timeStop.toCharArray();
if(lol[0]=='0' && lol[1]=='0'){ …Run Code Online (Sandbox Code Playgroud) 我是 kotlin 的新手,我创建了一个包含 when 语句和 IntelliJ 建议我删除 else 分支的方法。我不确定为什么。知道为什么我需要在这里删除 else 分支吗?这是代码:
companion object{
@Synchronized fun getDriver(
url: String,
desiredCapabilities: DesiredCapabilities,
mobilePlatform: MobilePlatform)
: AppiumDriver<WebElement> =
when(mobilePlatform){
MobilePlatform.ANDROID -> AndroidDriver<WebElement>(URL(url), desiredCapabilities)
MobilePlatform.IOS -> IOSDriver<WebElement>(URL(url), desiredCapabilities)
else -> throw RuntimeException("Cannot get the driver")
}
}
Run Code Online (Sandbox Code Playgroud) 如下所述,我有两节课。我想创建两个class A.
我想从现有实例 obj1 创建实例 obj2,并将 a3 属性的更新值为"Java".
我曾尝试使用Builder在下面的行,但它不起作用。
A obj2 = obj1.builder().a3("Java").build();
Run Code Online (Sandbox Code Playgroud)
我可以通过调用构造函数来做到这一点,但我只想做Builder模式。
@Builder(toBuilder = true)
@Data
class A {
String a1;
String a2;
String a3;
B b;
A(String b1, String b2, String b3, B b) {
this.a1 = b1;
this.a2 = b2;
this.a3 = b3;
this.b = b;
}
}
@Builder
@Data
class B {
String b1;
String b2;
String b3;
B(String b1, String b2, String b3) {
this.b1 = …Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习 OOP、构造函数和类方法。我的问题是,当我的构造函数被调用并且给定的值不起作用时。将创建一个对象,但它创建的值似乎不起作用或“应用”。也许代码会更好地解释它。我的圈子课是这样的:
public class MyCircle {
double radius;
public MyCircle() {
}
public MyCircle(double radius) {
}
final double pi = 3.14159;
public double getRadius() {
return radius;
}
public double getCircumference() {
return radius*pi;
}
public double getArea() {
return radius*radius*pi;
}
}
Run Code Online (Sandbox Code Playgroud)
对我来说似乎没问题,但是当我尝试从这样的测试类中使用它时:
public class MyCircleTest {
public static void main(String[] args) {
double radius = 26.5;
MyCircle myCoolCircle = new MyCircle(radius);
System.out.println("Circumference of myCoolCircle: " + myCoolCircle.getCircumference() );
System.out.println("Area of myCoolCircle: " + myCoolCircle.getArea());
Run Code Online (Sandbox Code Playgroud)
输出内容为:
myCoolCircle 的周长:0.0 …