【问题标题】:How to Split char or string using \ symbol? [closed]如何使用 \ 符号拆分字符或字符串? [关闭]
【发布时间】:2013-05-30 21:40:07
【问题描述】:

如何在 C 编程中拆分字符。

下面是代码。

char aa=Sanju\bala.

我想将 aa 拆分为 Sanju 和 bala 等两个值。 我该如何解决这个问题?

谢谢 三重

【问题讨论】:

    标签: c++ c window


    【解决方案1】:

    使用strtok:

    /* strtok example */
    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
      char str[] ="- This, a sample string.";
      char * pch;
      printf ("Splitting string \"%s\" into tokens:\n",str);
      pch = strtok (str," ,.-");
      while (pch != NULL)
      {
        printf ("%s\n",pch);
        pch = strtok (NULL, " ,.-");
      }
      return 0;
    }
    
    Output: 
    
    Splitting string "- This, a sample string." into tokens:  
    This 
    a  
    sample  
    string
    

    【讨论】:

    【解决方案2】:
    string str = "Sanju\bala";
    string[] splittedString = str.Split('\');
    

    希望这会有所帮助。 :):)

    【讨论】:

    • 不是 vc++...如何添加字符串头文件?
    • 你能贴一些代码吗,你想在哪里实现它。
    猜你喜欢
    • 2016-07-05
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-22
    相关资源
    最近更新 更多