Results 1 to 4 of 4

Thread: char Array := String

  1. #1
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default char Array := String

    How would I do this? I know it's automatic in Java, but not in Pascal

  2. #2
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Sin View Post
    How would I do this? I know it's automatic in Java, but not in Pascal
    Simba Code:
    var
      c : Array of Char;
      s : string;
      i : integer;
    begin
      c := ['h', 'e', 'l', 'l', 'o'];
      s := '';

      writeln(length(c));
      for i := 0 to 4 do
      begin
        setlength(s, i + 1); //you really dont need this, it just adds the array length of 's' to the first element
        s := s + c[i];
        writeln(s);
      end;
    end.

    Code:
    5
    5h
    5he
    5hel
    5hell
    5hello
    Last edited by Awkwardsaw; 07-30-2013 at 01:35 AM.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  3. #3
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    For what do you need a TCharArray? Since you can already do YourString[index]
    Working on: Tithe Farmer

  4. #4
    Join Date
    Aug 2013
    Posts
    35
    Mentioned
    0 Post(s)
    Quoted
    16 Post(s)

    Default

    Simba Code:
    function CharArrToStr ( CharArr : array of char) :string;
    var i,h : integer;
    begin
       Result := '';
       h := high(CharArr);
       for i:= 0 to h do
        Result := Result + Chararr[i];
    end;

    function StrToCharArr ( str : string) : array of char;
    var i,h : integer;
    begin
      h := high(str);
      setlength(Result,h);
      for i :=0 to h-1 do
        Result[i] := str[i+1];
    end;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •