logo
  • 教程列表
  • SO官方文檔
  • 字串
    • 反轉一個字串
    • 測試空字串或空字串
    • 將字串轉換為 ubyte,反之亦然
  1. StackOverflow 文件
  2. D Language 教程
  3. 字串
  4. 反轉一個字串

反轉一個字串

Created: November-22, 2018

string 定義為 alias string = immutable(char)[];:所以需要使用 dup 來製作一個可變的 char 陣列,然後才能反轉:

import std.stdio;
import std.string;

int main() {

    string x = "Hello world!";
    char[] x_rev = x.dup.reverse;
    
    writeln(x_rev); // !dlrow olleH
    
    return 0;

}
  • 測試空字串或空字串
  • 字串

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明