OK, related to http://www.adventuregamestudio.co.uk/yabb/index.php?topic=44702.msg597577 I decided to code up a function to remove illegal characters in filenames in strings (and to replace spaces with underscores). So far, this is what I have:
String StripChars (String ToStrip)
{
String StrippedTo;
char StripLook = 0;
int Count = 0;
while (Count < ToStrip.Length)
{
StripLook = ToStrip.Chars [Count]; // Get the char at the current position in the string to strip.
if (StripLook == ' ')
{
StripLook = '_';
}
StrippedTo = StrippedTo.AppendChar (StripLook);
Count++;
}
return (StrippedTo);
}
Except it doesn't work. In the function, on the line that should append the character to the string that is to be returned as a filename-safe version, it's giving a "Null pointer referenced" error. I have a suspicion this might be due to the use of a char in there. But can anyone else help out here?
Thanks.
You need to initalise StrippedTo
line 3:
String StrippedTo = "";
Quote from: Calin Leafshade on Wed 26/10/2011 14:27:02
You need to initalise StrippedTo
line 3:
String StrippedTo = "";
Yup, figured it out just a minute ago!
That's something to keep in mind with the new-style String type is that although you don't use normal pointer nomenclature (ie., no asterisk), it is internally still a pointer, and pointer logic still (very much!) applies.
That does actually make it possible to make String parameters to functions optional, so it certainly has benefits. ;)