我试图将图中的字体更改为 Times New Roman,但由于某种原因,x 轴标签中指数的字体没有改变。
我已将全局参数设置如下:
plt.rcParams["font.family"] = "Times New Roman"
除花括号内的部分外,其他都工作正常。
plt.xlabel("Stromdichte A cm$^{-2 test}$", fontsize=40)
当尝试获取无界字符串的第一个或最后一个索引时,如下程序所示
with Ada.Strings; use Ada.Strings; -- for `Backward`
with Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
procedure Foo is
package U_Str renames Ada.Strings.Unbounded;
S : U_Str.Unbounded_String := U_Str.To_Unbounded_String ("example unbounded string");
I : Natural := U_Str.Index (Source => S,
Pattern => "s",
Going => Backward,
From => S'Last);
begin
Put_Line (I'Image);
end Foo;
GNAT 抱怨U_Str.Unbounded_String
自己是私有类型:
$ gnatmake foo.adb
x86_64-linux-gnu-gcc-10 -c foo.adb
foo.adb:12:41: prefix for "Last" attribute may not be private type
gnatmake: "foo.adb" compilation error
我不明白这一点,同样的程序用常规方法String
可以正常工作:
with Ada.Strings; use Ada.Strings; -- for `Backward`
with Ada.Strings.Fixed;
with Ada.Text_IO; use Ada.Text_IO;
procedure Foo is
package F_Str renames Ada.Strings.Fixed;
S : String := "example fixed string";
I : Natural := F_Str.Index (Source => S,
Pattern => "s",
Going => Backward,
From => S'Last);
begin
Put_Line (I'Image);
end Foo;
$ gnatmake foo.adb
x86_64-linux-gnu-gcc-10 -c foo.adb
x86_64-linux-gnu-gnatbind-10 -x foo.ali
x86_64-linux-gnu-gnatlink-10 foo.ali
$ ./foo
15
无界字符串没有'First
和'Last
属性吗?Ada 参考手册只说明
下列属性是针对前缀 A 定义的,该前缀 A 属于数组类型(在任何隐式取消引用之后),或表示受约束的数组子类型
但它没有提到任何有关私有类型的信息。这是 GNAT 错误还是我遗漏了什么?
我正在尝试在 bash 中执行一些文件管理,并且我有以下格式的字符串:
1 dir/hello.txt
2 dir2/bar.jpg
当我运行这个替换时,${FOO/[:space:]*/Hello}
我得到了这个结果:1 dir/hHello
目标是将第一个空格后的所有内容(包括空格)替换为Hello
我觉得这似乎是个 bug。在这种情况下,请确认,我会将问题上报。
我提供了两种不同的计算字符串长度时切换段的实现。我不明白为什么我们要切换额外段和数据段,或者更准确地说,将数据段(寄存器 DS)的内容复制到额外段(寄存器 ES)。如果我删除这些行push ds
,pop es
结果不会改变,但是当我les di, [bp+4]
用替换时mov di, [bp+4]
,屏幕上会显示消息,但带有一堆其他不同的字符。
为什么会发生这种情况?我是装配方面的新手。
org 0x0100
jmp start
message: db 'Hello world!', 0 ; First string to be concatenated
; Subroutine to calculate the length of a string
; Takes the segment and offset of a string as parameters
strlen:
push bp
mov bp, sp
push es
push cx
push di
les di, [bp+4] ; Point es:di to string
mov cx, 0xffff ; Load maximum number in cx
xor al, al ; Load a zero in al
repne scasb ; Find zero in the string
mov ax, 0xffff ; Load maximum number in ax
sub ax, cx ; Find change in cx
dec ax ; Exclude null from length
pop di
pop cx
pop es
pop bp
ret 4
; Subroutine to print a string
; Takes the x position, y position, attribute, and address of a null-terminated string as parameters
printstr:
push bp
mov bp, sp
pusha
push di
push ds ; Push segment of string
mov ax, [bp+4]
push ax ; Push offset of string
call strlen ; Calculate string length
cmp ax, 0 ; Is the string empty?
jz exit ; No printing if string is empty
mov cx, ax ; Save length in cx
mov ax, 0xb800 ; Video memory base address
mov es, ax ; Point es to video base
mov al, 80 ; Load al with columns per row
mul byte [bp+8] ; Multiply with y position
add ax, [bp+10] ; Add x position
shl ax, 1 ; Turn into byte offset
mov di, ax ; Point di to required location
mov si, [bp+4] ; Point si to string
mov ah, [bp+6] ; Load attribute in ah
cld ; Clear direction flag for auto-increment mode
nextchar:
lodsb ; Load next char in al
stosw ; Print char/attribute pair
loop nextchar ; Repeat for the whole string
exit:
pop ds
pop di
popa
pop bp
ret 8
start:
mov ax, 30
push ax ; Push x position
mov ax, 20
push ax ; Push y position
mov ax, 0x7 ; Blue on white attribute
push ax ; Push attribute
mov ax, message
push ax ; Push address of message
call printstr ; Call the printstr subroutine
mov ax, 0x4c00 ; Terminate program
int 0x21
替代版本:
push bp
mov bp, sp
pusha
push ds
pop es ; load ds in es
mov di, [bp+4] ; point di to string
mov cx, 0xffff ; load maximum number in cx
xor al, al
repne scasb
mov ax, 0xffff
sub ax, cx
dec ax
jz done
mov cx, ax
...
第一次在这里发帖,我发现 Sol 20 计算机的旧 1977 BASIC 程序中存在一些错误。
第一个错误是“第 4240 行的 DM 错误”:
4220 PRINT " TYPE IN -STOP- TO QUIT ANYTIME"
4230 PRINT
4240 DIM A$(30),B$(30),C$(45),D$(30),E$(30),L$(10),Z$(12)
4250 LET A$="NO SUCH ELEVATION IN MY TAPES, UNDER 360, PLEASE."
4260 PRINT " THE TANK IS ";E;" FEET AWAY."
如果我从第 4240 行删除“B$(30)”,程序将继续运行,但会出现下面的“第 4590 行的 BS 错误”:
4560 IF I<=0 THEN 5250
4570 IF S=0 OR Z=3 THEN 4590
4580 LET S=-S
4590 LET D=(2*X**3*SIN(2*W)*COS(.5*W)/G*4)
4600 LET D=INT(D/15-(3*S-7))
4610 PRINT
4620 PRINT " ";D;" FEET"
如果我删除“X”后面的一个“*”,程序就可以运行,但范围太小了。熟悉 BASIC 的人可能都能发现错误或提出一些建议。
以前,当我使用 .NET 8 时,我可以在语句String.Join
中使用,如以下代码所示:Select
IQueryable
var receiveTransactions = await repository.Context.Set<ReceiveTransaction>()
.Select(x => new ThirdPartyTransactionReportModel
{
Date = x.Created,
Customer = string.Join(" - ", x.CustomerIdentity.Customer.Name, x.CustomerIdentity.Customer.Type, x.CustomerIdentity.Customer.Nationality.Name),
})
.ToListAsync();
但是,升级到 .NET 9 后,我遇到一个错误:
表达式树不能包含 ref struct 或受限类型“ReadOnlySpan”的值。
请提供任何解决方案或替代方案来解决此问题。
我有一个名为 BB_NP 的变量,我想将该内容(字符串)添加到带有日期/时间的输出文本文件中,所以只是一个基本的日志文件。
添加内容-路径“。\LogFile.txt”-值$(Get-Date) ($BB_NP)
每次我尝试时,无论采用何种组合(包装或不包装等),它都只能执行一项,而不能同时执行两项,我相信这是由于两种不同类型的数据造成的。
我怎样才能将其写入文本文件、日期/时间,然后连接 BB_NP 变量的内容?
谢谢!。
我正在尝试创建我期望从子程序 (GetAllPosition) 获得的内容。我不知道RsultOfPostionAndLength
在代码中哪里使用才能获得预期的输出
我对()的输出的期望RsultOfPostionAndLength
:
MultiSplit 的用法{"C", "B", "A"}
为: 55-5 '}666[' 61-5']777(' 67-3')8[' 71-6']hhhy('
MultiSplit 的用法{"A", "B", "C"}
为: 27-6 ']1111{' 34-4'}22(' 39-7')33333{' 47-3'}4{' 51-3 '}5{' 55-5'}666[' 78-4')99{' 83-5'}999['
Dim RsultOfPostionAndLength As List(Of String) 'Pattern is Position of String And Length Of Find
' 'MultiSplit' For {"C", "B", "A"} is: 55-5 '}666[' 61-5']777(' 67-3')8[' 71-6']hhhy('
' 'MultiSplit' For {"A", "B", "C"} is: 27-6 ']1111{' 34-4'}22(' 39-7')33333{' 47-3'}4{' 51-3 '}5{' 55-5'}666[' 78-4')99{' 83-5'}999['
Sub Setup()
Dim inString As String = "}666[]777([}666[]777(]00[A]1111{C}22(B)33333{C}4{C}5{C}666[A]777(B)8[A]hhhy(B)99{C}999[A]101010}666[]777("
Dim MultiSplit As String() = {"C", "B", "A"}
GetAllPosition(1, inString.Length, inString, MultiSplit, 0)
End Sub
Sub GetAllPosition(LastIdx As Integer, LastLen As Integer, inString As String, MultiSplit As String(), Level As Integer)
Dim spl As String() = Split(inString, ",")
Dim body As String = Mid(inString, LastIdx, LastLen)
'Dim LastIdx As Integer = spl(0)
Dim results As New List(Of String)
Dim Find As String = MultiSplit(Level)
Dim last As Integer = LastIdx
Dim index As Integer = -1
Do Until body.Length <= index
index = body.IndexOf(Find, index + 1)
If index = -1 AndAlso body.Length > last Then
index = body.Length
End If
Dim lenTexxt As Integer = Math.Abs(last - index) + 1
Dim part1 As String = Mid(body, last, lenTexxt)
Dim part As String = Mid(inString, last, lenTexxt)
Dim b As Boolean = MultiSplit.Skip(Level + 1).All(Function(c) part.IndexOf(c, comparisonType:=StringComparison.OrdinalIgnoreCase) > -1)
If b Then
results.Add(last & "," & lenTexxt & "," & part)
End If
last = index + 2
Loop
Level += 1
For Each g In results
Dim spl2 As String() = Split(g, ",")
GetAllPosition(spl2(0), spl2(1), inString, MultiSplit, Level)
Next
End Sub
我有时需要截断字符串以适应特定数量的字节。在 Go 中执行此操作的问题是,如果您这样做s[:1_000_000]
,假设这s
是一个有效的utf-8 字符串,您可能最终会在 utf-8 代码点的中间进行切割,该代码点可能为 1~4 个字节长,从而留下无效的符文。
有些人(以及接受过他们思想培训的法学硕士)会尝试使用utf8.ValidString
或for i := range s
来做到这一点,因为这两种方法都可以确保符文有效。但是,这些人将在线性时间内完成恒定时间任务。
我编写了一个恒定时间的安全截断函数:
import "unicode/utf8"
// UTF8SafeTruncateNBytes Truncates a **valid** utf-8 string `s` to `n` bytes (not n UTF-8 characters),
// ensuring that the string is not truncated in the middle of a UTF-8 character.
func UTF8SafeTruncateNBytes(s string, n int) string {
if n >= len(s) {
return s
}
for i := n; i >= n-3 && i >= 0; i-- {
if utf8.RuneStart(s[i]) {
return s[:i]
// Edit: This was:
//if r, size := utf8.DecodeRuneInString(s[i:]); r != utf8.RuneError {
// return s[:i+size]
//}
// but got fixed because of the picked solution. This implementation is now correct,
// and, in fact, equivalent, except that it only checks one byte instead of backing up forever.
}
}
// Fallback in the case that the user lied, and passed a string that is not a valid utf-8 string.
// It would be wise to return an error or "" here if this is a standard-library
// function to allow the user to check for it.
return s[:n]
}
问题如下:
"unicode/utf8"
?似乎它的使用频率和复杂性恰好足以保证拥有标准库函数。我应该在他们的问题页面中提出它吗?