我的一个字符串是由几个字符串组成的,比如说 a,b,c 各有三段子字符串连接而成的a :  abcd       12345     asa
b :  hrtjfddd   153       bgde
c :  bds        8888888   dswegdf由于事先不知道每段子字符串的长度,所以不可能加上数量不等的空格来对齐
我想实现的功能就是,无论每个子字符串的长度是多少,他们占据的空间是相同的,西医各自字符串都是在相同位置开始的,就好像我们使用的 tab 建一样,在 pascal 或着 c 中有 /t 这样的格式的,请问再delphi 中如何实现

解决方案 »

  1.   

    如果是向文件中写入的话,或者是向控制台输出的话,可以用 Write(s: 8);这样保证它只占用 8 个字符的位置。
      

  2.   

    是向字符串中写入,上例中就是 a, b, c
      

  3.   

    to windindance(风舞轻扬) :还差一点啊,按你说的是这样:abcd    12345
    abd    12345我想实现的是这样:
    abcd    12345
    abd     12345应该怎么样呢?
      

  4.   

    //参考
    http://zswang.51.net/function/zsfunc0z.htmfunction StringAlign(mStr: string; mLength: Integer;
      mAlignment: TAlignment; mBackChar: Char = #32): string;
    var
      L: Integer;
      T: string;
    begin
      Result := mStr;
      L := Length(mStr);
      if L >= mLength then Exit;
      T := DupeString(mBackChar, mLength - L);
      case mAlignment of
        taLeftJustify: Result := Result + T;
        taRightJustify: Result := T + Result;
        taCenter: begin
          L := Length(T) div 2;
          Result := Copy(T, 1, L) + Result + Copy(T, L + 1, MaxInt);
        end;
      end;
    end; { StringAlign }
      

  5.   

    ShowMessage('a'+^I+'b'#13'abc'+^I+'ddd');
      

  6.   

    to li_zhifu(东北人) :什么意思啊?
      

  7.   

    li_zhifu(东北人) ,是使用了控制字符吧
      

  8.   

    就是说,在字符串里,^I代表一个Tab(制表位),所以上述就会弹出一个对话框
    a       b
    abc     ddd
      

  9.   

    to li_zhifu(东北人) 问题依旧阿我里面有中文字的,我是这样的: a:'东北人' + ^I + '12345';
    b: '东北' + ^I + '12345';结果
    a:东北人     12345
    b:东北      12345
      

  10.   

    //声明StringAlign()函数不要忘记uses StrUtils; //for Delphi6StringAlign('东北人', taLeftJustify, 8) + StringAlign('12345', taLeftJustify, 8) + #13#10 +
    StringAlign('东北', taLeftJustify, 8) + StringAlign('12345', taLeftJustify, 8) + #13#10 +
    StringAlign('东', taLeftJustify, 8) + StringAlign('12345', taLeftJustify, 8) + #13#10;StringAlign('东北人', taRightJustify, 8) + StringAlign('12345', taRightJustify, 8) + #13#10 +
    StringAlign('东北', taRightJustify, 8) + StringAlign('12345', taRightJustify, 8) + #13#10 +
    StringAlign('东', taRightJustify, 8) + StringAlign('12345', taRightJustify, 8) + #13#10;