+ -
当前位置:首页 → 问答吧 → 一个简单的字符串操作

一个简单的字符串操作

时间:2010-09-14

来源:互联网

假如一个字符串是"aa\0bb\0cc\0dd0d\0aa\00\0\0";

有没有最简单的算法?

结果为:"aa\0bb\0cc\0dd0d\0aa\01\0\0";

作者: youzlm   发布时间: 2010-09-14

str[16] = '\01';

作者: hellioncu   发布时间: 2010-09-14

回复 hellioncu


   

作者: cobras   发布时间: 2010-09-14

什么需求都没有,毛算法。。

作者: pengjianbokobe   发布时间: 2010-09-14

本帖最后由 cobras 于 2010-09-14 15:58 编辑
  1. #include <stdio.h>
  2. #include <string.h>

  3. int main(void)
  4. {
  5.         char s[] = "aa\0bb\0cc\0dd0d\0aa\00\0";
  6.         char *p;

  7.         for (p = s; *p != '\0'; p += strlen(p)) {
  8.                 if (strcmp(p, "0") == 0) {
  9.                         strcpy(p, "1");
  10.                 }
  11.         }
  12.         for (p = s; *p != '\0'; p += strlen(p)) {
  13.                 printf("%s\n", p);
  14.         }
  15.         return 0;
  16. }
复制代码

作者: cobras   发布时间: 2010-09-14

  1. char *p1 = "aa\0bb\0cc\0dd0d\0aa\00\0";
  2. char *p2 = "aa\0bb\0cc\0dd0d\0aa\01\0\0";

  3. p1 = p2;
复制代码

作者: efolzl   发布时间: 2010-09-14

本帖最后由 dibug 于 2010-09-14 18:27 编辑
  1.   1 assume  cs:code,ds:data
  2.   2 data    segment
  3.   3 string  db      'aa\0bb\0cc\0dd0d\0aa\00\0\0'
  4.   4 data    ends
  5.   5 code    segment
  6.   6 start:
  7.   7         mov ax,data
  8.   8         mov ds,ax
  9.   9         mov cx,lengthof string
  10. 10         mov bx,offset string
  11. 11 s:      mov al,[bx]
  12. 12         cmp al,30h
  13. 13         jz s1
  14. 14         jmp jx
  15. 15 s1:     cmp al,[bx+1]
  16. 16         jz s2
  17. 17         jmp jx
  18. 18 s2:     inc byte ptr [bx+1]
  19. 19 jx:     inc bx
  20. 20         loop s
  21. 21         mov ah,4ch
  22. 22         int 21h
  23. 23 code    ends
  24. 24 end     start
复制代码

作者: dibug   发布时间: 2010-09-14

相关阅读 更多