(C ++)如何搜索字符串并用双引号替换每个双引号?

时间:2017-08-22 20:22:55

标签: c++ string

这样的工作可以吗?我看过导游,他们似乎没有用两个或更多个字符替换单个字符。

Option Explicit

Sub calculations_update()
    Application.DisplayStatusBar = False
    Application.ScreenUpdating = False

    Dim StartTime As Double    
    Dim SecondsElapsed As Double
    Dim i As Long

    StartTime = Timer

    Do While i < 95
        i = i + 1
        Range("DstRng1").Value = Range("SrcRng1").Value
        Range("DstRng2").Value = Range("SrcRng2").Value
        Range("DstRng3").Value = Range("SrcRng3").Value
        Range("DstRng4").Value = Range("SrcRng4").Value
        Range("DstRng5").Value = Range("SrcRng5").Value
    Loop

    SecondsElapsed = Round(Timer - StartTime, 2)
    MsgBox "The update was successful in " & SecondsElapsed & " seconds", vbInformation
    Application.DisplayStatusBar = True
    Application.ScreenUpdating = True
End Sub

1 个答案:

答案 0 :(得分:0)

您的代码无法按预期执行。

您告诉std::string将2个字符的常量'\"\"'分配到包含单个字符的插槽中。

搜索您最喜爱的C ++参考的basic_string section,找到方法,将插入 字符串或多个字符添加到字符串中

编辑1 - 示例

std::string::size_type position = 0;
position = s.find('"');
while (position != std::string::npos)
{
  s.insert(position, "\"");
  position += 2;
  position = s.find('"');
}