Click to See Complete Forum and Search --> : String File names


seubjoh
August 13th, 2009, 06:50 PM
So I have a stack of pictures that I need to read and I've named them target0, target1, target2, etc. but to type each of those into a string like:

textureFilename[0] = "target1.png";


is inconvenient. Is there a way I can make the number in the string an integer value, similar to a printf, so that I can just put this in a loop?

What I mean by a printf is:

printf("target%d.png", i);

is there something I can do like this for entering a string name in?

Thanks!

monalin
August 13th, 2009, 06:52 PM
I think this is what you're looking for.


String.Format("target{0}d.png", i);

seubjoh
August 13th, 2009, 06:59 PM
that worked awesome thanks for the help

BigEd781
August 13th, 2009, 07:04 PM
monalin's suggestion is the way to go, but you could have always just concatenated the string or used a StringBuilder inside of the loop.