C ++从char类型中删除引号

时间:2016-09-19 17:31:36

标签: c++ quote

需要测试变量删除引号。怎么样?

char test[] = "\"C:\\hello\"";

if(test[0] = '"')
{
 // test variable 0 index to blank
}

2 个答案:

答案 0 :(得分:1)

由于您使用的是Windows,请调用Windows API中的PathUnquoteSpaces函数。

PathUnquoteSpaces(test);

答案 1 :(得分:0)

要删除字符数组中的字符,您需要使用剩余文本覆盖插槽。

原文:

+---+---+---+----+   
| " | C | : | \0 |  
+---+---+---+----+   
      |  
  +---+  Copy from original.
  |
  V  
+---+---+----+----+   
| C | : | \0 | \0 |  
+---+---+----+----+   

当目的地重叠时,请参阅memmove进行复制。

更简单的解决方案是对所有多字符文本及其方法使用std::string