帮助修剪其返回字符 MIPS 的字符串输入

发布于 2024-10-06 07:36:01 字数 362 浏览 0 评论 0原文

我正在用 MIPS 编写一个游戏,并输入一个玩家的名字。当我尝试打印类似以下内容时:

li $v0, 4  
la $a0, playerName  
syscall

li $v0, 4  
la $a0, strEnd     #strEnd = ("'s Hand: ")  
syscall

所以我希望它显示:

"playerName's Hand: "

所有内容都不会出现在同一行上。相反,我得到:

"playerName  
's Hand: "

我的问题是如何从我输入的名称中删除换行符?谢谢

I'm writing a game in MIPS and I take in a player's name. When I try to print something like:

li $v0, 4  
la $a0, playerName  
syscall

li $v0, 4  
la $a0, strEnd     #strEnd = ("'s Hand: ")  
syscall

So I want it to display:

"playerName's Hand: "

Everything doesn't appear on the same line. I instead get:

"playerName  
's Hand: "

My question is how can I strip the new line character from the name I took in? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

世俗缘 2024-10-13 07:36:01
# Your code to take a player's name

    li $s0,0               # Set index to 0
remove:
    lb $a3,word($s0)      # Load character at index
    addi $s0,$s0,1        # Increment index
    bnez $a3,remove    # Loop until the end of string is reached
    beq $a1,$s0,skip      # Do not remove \n when it isn't present
    subiu $s0,$s0,2     # Backtrack index to '\n'
    sb $0, word($s0)        # Add the terminating character in its place

删除换行符:)

# Your code to take a player's name

    li $s0,0               # Set index to 0
remove:
    lb $a3,word($s0)      # Load character at index
    addi $s0,$s0,1        # Increment index
    bnez $a3,remove    # Loop until the end of string is reached
    beq $a1,$s0,skip      # Do not remove \n when it isn't present
    subiu $s0,$s0,2     # Backtrack index to '\n'
    sb $0, word($s0)        # Add the terminating character in its place

Removes the newLine character :)

作妖 2024-10-13 07:36:01

遍历包含玩家姓名的字符串,直到到达空字符。存储该位置。然后在 pos-1 处放置一个空字符。 (我认为你也必须把它放在 pos-2 处,因为换行符有时是 2 个单独的字符。)

Go through the string containing the player name, until you reach the null character. Store that position. Then place a null character at pos-1. (I think you'll have to put it at pos-2 as well, since a newline is sometimes 2 separate characters.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文