I was wondering if Java has the equivelent of the visual basic String() function. What it does is return a string containing a given number of a certain character. Eg: a = String(23,"a") would return a string containing 23 a's. Does such a function exist in Java?
dont believe so matey.. Could be wrong tho check here for strings http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html Laters Jon
Like Jon, I'm not sure if one exists, but you could probably write one using a for loop. I don't really know java syntax, so this will be a rough guess. You'll have to clean it up, use proper variable scope, etc... PHP: Function LetterString(int_length,str_letter) { outputString = ""; for (i=int_length; i > 0; i--) { outputString = outputString + str_letter; } } Again, the syntax is wrong and you'll need to fill in a thing or two, but it should work.
yeah like complexprocess a simple function would work in a global tools class or sommat. Same code but perhaps with carling driven java syntax behind it Laters Jon Code: public String LetterString(int length,String letter) { String outputString = ""; for (int i=0; i <= length; i++) { outputString = outputString + letter; } return outputString; } or mebbe Code: public String LetterString(int length,char letter) { String outputString = ""; for (int i=0; i <= length; i++) { outputString = outputString + String.valueOf(letter); } return outputString; }
if I had to guess.... Code: string a; a = 23+"a"; System.out.println(a); again, I'm probably wrong... /me attemps compilation edit: nope
Yeah I can write my own method to do what I want. I was just wondering if Java had the same function vb has. I think Jon's code would work except shouldn't i start at 1 not 0?
Yes because i put an <= sign if it had just been a < it would have worked okay. I think Without actually writing it and compiling it i couldnt test it tho LOL Laters Jon