0

Hello, anyone can help me with the conversion of single quotes in a string to double quotes? Am new to Ruby programming and still learning around on how to use it properly.

I have an example in Delphi, which I want to make compatible with Ruby:

function ReplaceSingleQuote(AText: String): String;
begin
    Result := '';
    if Length(AText) = 0 then
        Exit;
    Result := StringReplace(AText, '''', '''''', [rfReplaceAll]);
end;
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Ritesh_4
0

Use gsub. First argument is the item you want to change (can be string or regex) the second is what you want to change it to.

s = "this 'string' has embedded single 'quotes'"
s.gsub("'", '"')
# => "this \"string\" has embedded single \"quotes\"" 
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.