StrGetCharAt

Started by AnInhumer, Wed 08/06/2005 20:27:18

Previous topic - Next topic

AnInhumer

How can you convert the char returned by the StrGetCharAt into a string so that it can be used in the standard functions.

strazer

StrFormat(thestring, "%c", thechar);

AnInhumer

Thank you, I hadn't thought of that.

I can understand the use of char but why not a string?
All the functions use int or string meaning the fact it returns something is useless

Someone is now going to point out why it isn't

Denzil Quixode

Chars can be useful in certain circumstances since you can use ranges to find if a particular character is an upper case letter, a lower case letter, a number, etc. as opposed to StrComping a string to every single value.

It might be useful to have a substring-extracting function aswell, though.

Gilbert

Quote from: AnInhumer on Wed 08/06/2005 21:13:27
I can understand the use of char but why not a string?
All the functions use int or string meaning the fact it returns something is useless

Because AGS cannot return a string in a function, nor can strings be used directly in arithmetic expressions.
For example you cannot do stuff like:
string blah = "HAHAHA";
or
function MakeString(int num){
  string blargh;
  //blahblablabla
  return blargh;
}

You need to use the Str*() functions for string operations.

strazer

QuoteIt might be useful to have a substring-extracting function aswell, though.

You mean something like that?:

Code: ags

function StrCopyEx(string destination, string source, int start, int length) {
  StrCopy(destination, "");
  int end = start + length;
  while (start < end) {
    char letter = StrGetCharAt(source, start);
    StrFormat(destination, "%s%c", destination, letter);
    start++;
  }
}

monkey0506

That would be a good one to add to the StringAdditions SM.  I found a problem with one of the functions in there anyway and just haven't updated it since fixing it.  I'll work on that tomorrow.  Erm... Later, today? :o ('Tis past midnight already?)

SMF spam blocked by CleanTalk