Results 1 to 14 of 14

Thread: Eh, more help needed with Arrays, strings, chars, etc.

  1. #1
    Join Date
    Jul 2007
    Location
    America
    Posts
    421
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Eh, more help needed with Arrays, strings, chars, etc.

    Mkay, so I'm making a trading function that uses the traders name with some other stuff (might release eventually), and I need some help.

    1)Any way to make a string into an array of char?

    2) to find if a single char is part of a string, like see if there is an 'e' in a certain word.

    3)Make a nickname out of a string, like take the middle 3 letters?

    Thanks in advance.
    I dunno, those asians are pretty difficult to out-auto, legend has it they don't need sleep or food...~tim0suprem0
    Activity is on the decline - school's got me
    Check out my tutorial[s] on Color Finding!||Procedures and Functions!

  2. #2
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    man, i have no idea in scar, but maybe you could make a c++ plugin that does it. is there even a character type in scar?

    if you can do one, you can pretty much do 2 and 3 easily

    my suggestion is modify the function that is finding your text so that it returns an array of chars

    have a loop that finds the chars one at a time, and places them in the same array

    once you have that, find the length of the array with getarraylength. now have a repeat until loop that goes something like this:

    SCAR Code:
    repeat
        i:=i+1;
      until character[i]='e' or i={length of the array + 1};
      if (i={length of array + 1})then result= false
      else result= true;

    do you understand how that would work?
    so "i" starts at 0 and increases by 1 each time. Each time, it checks whether the character in the array is equal to e. If it is, it ends the loop. if not, then it continues, checking the next part of the array, because "i" increases by one. if "i" is the value of how long the character array is +1, then it has gone through all the characters in the array, so 'e' is not in the array. It ends the loop, and if i is equal to the length of the array + 1, it returns false; the loop ended because it finished checking all the characters. if it is not equal to the length of the character array, then it stopped early because it found 'e', therefore, e was in the string.


    for the user nick thing, that would be a little harder. you would automatically start at i:=1 because the first char is never used. you would then go through the characters, and hopefully find 3 char in a row before finding a space. If a space is found, then it would skip the next char (i:=i+2) and then try again.

    edit: might want to explore the scar functions stringofchar, strget, strset, and length, they might help, strget looks right, just use a for loop and strget all the chars in the string



    I hope this helped. I am going to go research some srl or scar functions that may help solve one of your problems. If you have any more questions, please feel free to pm me or talk with me on msn.

    Macrosoft

  3. #3
    Join Date
    Aug 2007
    Posts
    429
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Kik View Post
    Mkay, so I'm making a trading function that uses the traders name with some other stuff (might release eventually), and I need some help.

    1)Any way to make a string into an array of char?

    2) to find if a single char is part of a string, like see if there is an 'e' in a certain word.

    3)Make a nickname out of a string, like take the middle 3 letters?

    Thanks in advance.
    for #1)
    Kinda confused? Do you mean like so the string 'Hello' would be returned as an array of ['H', 'e', 'l', 'l', 'o']?

    If so I made these:
    SCAR Code:
    Function StringToCharArray(TheString: string): TStringArray;
    var
      i : Integer;
    begin
      for i := 1 to Length(TheString) do
      begin
        SetLength(Result, i);
        Result[i - 1] := copy(TheString, i , 1);
      end;
    end;


    //EXAMPLE of use:
    begin
      WriteLn(BoolToStr(InStrArr('o', StringToCharArray('hello'), False)));
      //will say if the letter 'o' is found in the array of chars made by the function StringToCharArray('hello')
    end.

    for #2)
    Maybe use:
    PHP Code:
    function pos(substrsstring): LongInt;
    Returns position of substring in stringReturns 0 if not found
    Example:
    SCAR Code:
    begin
      TheString := 'Bobby';
      if not (pos('o', TheString)=0) then //if 'o' IS in the TheString then..
      if (pos('o', TheString)=0) then //if 'o' IS NOT in the TheString then..
    end.

    for #3)
    Maybe use:
    PHP Code:
    function copy(sstringifromicountLongInt): string;
    Returns part of the string (Copy('abcde',2,3would return 'bcd'
    Example:
    SCAR Code:
    begin
      TheString := 'Bobby';
      Nickname := Copy(TheString, 2, 3);
      //would make nickname 'obb'
    end.

    Hope this helps =]
    Derek-

  4. #4
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    simpler way to convert string to array of chars:

    SCAR Code:
    for i:=1 to length({the String}) do
    begin
      character[i-1]:=strget({the string}, i);
    end;

  5. #5
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    1. A string is already an Array of chars, this will work:
    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 1 to 5 do
        Writeln(strings[i]);
    end.

    2.
    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 1 to Length(strings) do
        if (strings[i] = 'e') then Writeln(strings[i]);
    end.

    3.
    I've done this before for a little script I made I'm getting the code now:
    SCAR Code:
    program New;

    const
      PlayerName = 'randomname';   //Name
      NoNickChars = 3;         //Number of characters for the nickname

    var
      NickChar: Integer;

    function GetNick: string;
    begin
      NickChar := Floor(Length(PlayerName) / 2) - Floor(NoNickChars / 2);
      Result := Copy(PlayerName, NickChar, NoNickChars);
    end;

    begin
      Writeln(GetNick);
    end.

  6. #6
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    wow, that makes things a lot easier!

    check out my sig, the top link has a link to a great user nick setter (by me of course )<--yours wont work if there is a space in the name


    Edit:yay 200th post!

  7. #7
    Join Date
    Jul 2007
    Location
    America
    Posts
    421
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for all the help guys.
    I dunno, those asians are pretty difficult to out-auto, legend has it they don't need sleep or food...~tim0suprem0
    Activity is on the decline - school's got me
    Check out my tutorial[s] on Color Finding!||Procedures and Functions!

  8. #8
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    1. A string is already an Array of chars, this will work:
    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 1 to 5 do
        Writeln(strings[i]);
    end.

    2.
    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 1 to Length(strings) do
        if (strings[i] = 'e') then Writeln(strings[i]);
    end.

    3.
    I've done this before for a little script I made I'm getting the code now:
    SCAR Code:
    program New;

    const
      PlayerName = 'randomname';   //Name
      NoNickChars = 3;         //Number of characters for the nickname

    var
      NickChar: Integer;

    function GetNick: string;
    begin
      NickChar := Floor(Length(PlayerName) / 2) - Floor(NoNickChars / 2);
      Result := Copy(PlayerName, NickChar, NoNickChars);
    end;

    begin
      Writeln(GetNick);
    end.
    Zephyr owned the competition
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  9. #9
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Santa_Clause View Post
    Zephyr owned the compettion
    Yea.. Wootness!!

    Quote Originally Posted by Macrosoft View Post
    wow, that makes things a lot easier!

    check out my sig, the top link has a link to a great user nick setter (by me of course )<--yours wont work if there is a space in the name


    Edit:yay 200th post!
    Meh I made it in 30 seconds. Your one looks pretty good. I'll go through it soon. I suppose I could fix mine but I CBF and have no use for it.

  10. #10
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Santa_Clause View Post
    Zephyr owned the compettion
    what can i say, he did...

    i didn't post any actual code, i wanted him to try and code it himself, but dang, my way was really complicated

    ZephyrsFury-Do you know if there is a null character in the char array, like in c++?

  11. #11
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Ummm... I have no idea how to script c++... so what do you mean by a null character?

  12. #12
    Join Date
    Jul 2007
    Location
    Massachusetts
    Posts
    896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    in c++, the string "lalala", if in a char array, would need to have 7 char spaces. In order to hold "lala", the array would have to have 5 parts. by putting something in "", you say it is a string. This also automaticly adds a null character at the end of the string, to show the end of the string. Chars would be declared like this: char a= 'a', because there is no null character.

    to sum it up:

    in c++

    "abcd" = 'a', 'b', 'c', 'd', '\0'

  13. #13
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Highly doubt you can do that in SCAR.

    By the way, when you split up a word into an array of char...isn't the first character [0], not [1]?

    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 1 to Length(strings) do
        if (strings[i] = 'e') then Writeln(strings[i]);
    end.

    I think it should be:

    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 0 to Length(strings) - 1 do
        if (strings[i] = 'e') then Writeln(strings[i]);
    end.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  14. #14
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Macrosoft View Post
    in c++, the string "lalala", if in a char array, would need to have 7 char spaces. In order to hold "lala", the array would have to have 5 parts. by putting something in "", you say it is a string. This also automaticly adds a null character at the end of the string, to show the end of the string. Chars would be declared like this: char a= 'a', because there is no null character.

    to sum it up:

    in c++

    "abcd" = 'a', 'b', 'c', 'd', '\0'
    I don't think that exists in scar because if you get the Length of a string, it returns the actual number of characters.

    Quote Originally Posted by Santa_Clause View Post
    Highly doubt you can do that in SCAR.

    By the way, when you split up a word into an array of char...isn't the first character [0], not [1]?

    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 1 to Length(strings) do
        if (strings[i] = 'e') then Writeln(strings[i]);
    end.

    I think it should be:

    SCAR Code:
    program New;
    var
      strings: string;
      i : integer;
    begin
      strings := 'hello';
      for i := 0 to Length(strings) - 1 do
        if (strings[i] = 'e') then Writeln(strings[i]);
    end.
    Thats what I originally thought but it doesn't work if you try your example (out of range error).

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. friendlist chars
    By Shuttleu in forum Research & Development Lounge
    Replies: 2
    Last Post: 06-02-2008, 03:52 PM
  2. Arrays, stuck on arrays
    By Camaro' in forum OSR Help
    Replies: 1
    Last Post: 03-08-2008, 02:02 AM
  3. new chars
    By raimis89 in forum OSR Help
    Replies: 9
    Last Post: 12-21-2006, 10:31 AM

Posting Permissions

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