Hello, I have some sample delphi codes which I want to convert to Ruby
for test purposes, anyone can help me:

1. Replace single quotes with double quotes:

function ReplaceSingleQuote(AText: String): String;
begin
    Result := '';
    if Length(AText) = 0 then
        Exit;
    Result := StringReplace(AText, '''', '''''', [rfReplaceAll]);
end;


2. ANSI Split Strings:

function  AnsiSplitStrings(const str: string;const separator: string =
',';Strings: TStrings = nil): TStrings;
var
   n: integer;
   p, q, s: PChar;
   item,sString: string;
begin
     if Strings = nil then
        Result := TStringList.Create
     else
         Result := Strings;
     if str='' then exit;
     if str[Length(str)] = separator then
        sString := AnsiLeftStr(str,Length(str)-1)
     else
         sString := str;

     try
        p := PChar(sString);
        s := PChar(separator);
        n := Length(separator);
        repeat
              q := AnsiStrPos(p, s);
              if q = nil then q := AnsiStrScan(p, #0);
              SetString(item, p, q - p);
              Result.Add(item);
              p := q + n;
        until q^ = #0;
     except
           item := '';
           if Strings = nil then Result.Free;
           raise;
     end;
end;

3. Check phone format:

function IsPhoneFormatCorrect(sPhoneNo: string): Boolean;
var iPos:integer;
begin
     if Length(sPhoneNo) > 0 then
        begin
             iPos := 1;
             Result := (Length(sPhoneNo) > 3) and (sPhoneNo[iPos] = '+')
and (AnsiPos('(',sPhoneNo) > 1) and (AnsiPos(')',sPhoneNo) >
(AnsiPos('(',sPhoneNo)+1));
        end
     else
         Result := true;
end;

T.I.A.

-- 
Posted via http://www.ruby-forum.com/.