请问如何把字符串从aaabbb变成aaaCCCbbb,及在串某一个位置插入一串形成新串??
用什么函数?
谢谢~

解决方案 »

  1.   

    nserts a substring into a string beginning at a specified point.UnitSystemCategoryString handling routinesprocedure Insert(Source: string; var S: string; Index: Integer);DescriptionInsert merges Source into S at the position S[index].Source is a string-type expression. S is a string-type variable of any length. Index is an integer-type expression. It is a character index and not a byte index.If Index is less than 1, it is mapped to a 1. If it is past the end of the string, it is set to the length of the string, turning the operation into an append.If the Source parameter is an empty string, Insert does nothing.Insert throws an EOutOfMemory exception if it is unable to allocate enough memory to accomodate the new returned string.
      

  2.   

    如果位子是由strpos得来的呢?
    上面这个函数返回值不是int类型,怎么转换阿~
      

  3.   

    s := 'aaabbb';
    insert('ccc', s, 4);此时s就是aaacccbbb了
      

  4.   

    嘻嘻,使用StringReplace("aaabbb","aaa","aaaCCC",[rfReplaceAll]);
      

  5.   

    哈哈,先查找 aaabbb 的中间不同位置
    var
      s:string;
    begin
      s:='aaabbb';
      for i:=0 to length(s)-1 do
      begin
        if s[i]<>s[i+1] then
          break;
      end;
      //其中i就是分割开的位置
      //下面自己添加插入就可以了饿
      

  6.   

    另外听说还有一种方法,因为 aaa和bbb是等长的,那么可以从中间插入数据。
      

  7.   

    将Source插入S中,Index为插入位置procedure Insert(var S: string; Source: string; Index: Integer);
    var
      len1,len2: Integer;
    begin
      len1:=Length(S);
      len2:=Length(Source);  if Index<0 then Index:=0
      else if Index>Len1 then Index:=Len1;  SetLength(S,Len1+Len2);
      CopyMemory(@S[Len2+Index+1],@S[index+1],Len1-index);
      CopyMemory(@S[Index+1],@Source[1],Len2);
    end;
      

  8.   

    我想搞一个:
    str1:='select ... from test'
    然后我想把str1变成:
    str1:='select ... into newtable from test'应该可以直接取到from位置的index,然后用insert函数
    可是如何去index?strpos返回值不是integer
      

  9.   

    何必那么麻烦了。开始你这样str:='';
    str1:='select ...'+str+' from test'以后你想加东西了。
    就把str赋值'into newtab'str:='into newtab';
    str1:='select ...'+str+' from test'
      

  10.   

    回复人:lili1(离奇) () 信誉:105 不是那样的,
    str1是动态生成的!
    预先无法确认阿!