HarmonyOS 如何实现有符号的数组

HarmonyOS
2024-12-23 14:50:23
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

参考示例如下:

import util from '@ohos.util';

function stringToSignedBytes(str: string): Int8Array {
  const encoder = new util.TextEncoder();
  const uint8Array = encoder.encodeInto(str);
  return new Int8Array(uint8Array);
}

@Entry
@Component
struct Index4 {
  @State message: string = 'Hello World';

  aboutToAppear(): void {
    let str: string = "字符转换问题";
    let signedBytes: Int8Array = stringToSignedBytes(str);
    console.log(signedBytes.toString());
    this.message = signedBytes.toString()
  }

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('Index4HelloWorld')
        .fontSize(20)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
    }
    .height('100%')
    .width('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-23 18:06:28
相关问题
HarmonyOS 现有组件扩展如何实现
354浏览 • 1回复 待解决
PopWindow效果实现有哪些?
1018浏览 • 1回复 待解决
Binder链接池实现有哪些方法?
1047浏览 • 1回复 待解决
Scrollerfling实现有什么好方案
1156浏览 • 1回复 待解决
数组嵌套数组场景懒加载实现
889浏览 • 1回复 待解决
数组列表如何实现数据双向同步?
951浏览 • 1回复 待解决
HarmonyOS AGC如何加载符号观测
651浏览 • 1回复 待解决
如何实现ArkTS与C/C++数组转换
1404浏览 • 1回复 待解决
如何实现对字节数组进行解压
2019浏览 • 0回复 待解决
编译so时如何去除符号
3558浏览 • 1回复 待解决
readonly修饰数组无法获取数组元素
2770浏览 • 1回复 待解决