doumao8355 2016-03-12 03:34
浏览 743
已采纳

Golang为什么这两个字符串不相等?

I copied and pasted these two strings (one from a Google Doc and one from terminal) – what the heck is going on? And how can I clean them up so they are the same?

package main

import "fmt"

func main() {
    fmt.Println([]byte("f6f77482e4394a21815b7090bc0185b4"))
    fmt.Println([]byte("f6f77482­e439­4a21­815b­7090bc0185b4"))
}

Returns:

[102 54 102 55 55 52 56 50 101 52 51 57 52 97 50 49 56 49 53 98 55 48 57 48 98 99 48 49 56 53 98 52]
[102 54 102 55 55 52 56 50 194 173 101 52 51 57 194 173 52 97 50 49 194 173 56 49 53 98 194 173 55 48 57 48 98 99 48 49 56 53 98 52]

Which are clearly two different byte arrays for the same string.

https://play.golang.org/p/_zd7tjqCZl

  • 写回答

2条回答 默认 最新

  • doutao8774 2016-03-12 03:54
    关注

    The second one has a number of "soft hyphen" (U+00AD) characters between the visible characters, the first one appearing between "482" and "e4". A soft hyphen is a character that's invisible unless it happens to be at the location of a line-break, then it appears as a hyphen. Did you copy-paste the code from a word processor or some other program that might have applied special text formatting to it?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),如何通过环岛的原理及完整代码
  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?
  • ¥15 c语言数据结构高铁订票系统