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;

Recommended Answers

All 2 Replies

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\"" 

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.