Development Help with Java

Discussion in 'Software' started by DeX, 28 Oct 2003.

  1. DeX

    DeX Mube Codder

    Joined:
    22 Jul 2002
    Posts:
    4,152
    Likes Received:
    3
    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?
     
  2. LaughingJon

    LaughingJon What's a Dremel?

    Joined:
    12 Feb 2003
    Posts:
    282
    Likes Received:
    0
  3. complexprocess

    complexprocess What's a Dremel?

    Joined:
    8 Jul 2002
    Posts:
    353
    Likes Received:
    0
    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_length0i--)
        {
        
    outputString outputString str_letter;
        }
    }
    Again, the syntax is wrong and you'll need to fill in a thing or two, but it should work.
     
  4. woodshop

    woodshop UnSeenly

    Joined:
    14 Oct 2003
    Posts:
    1,408
    Likes Received:
    8
    This what you looking to do? can post the source if needed.
     
  5. LaughingJon

    LaughingJon What's a Dremel?

    Joined:
    12 Feb 2003
    Posts:
    282
    Likes Received:
    0
    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;
    }
    
     
  6. Bruno_me

    Bruno_me Fake-ad‎min

    Joined:
    30 Mar 2003
    Posts:
    1,136
    Likes Received:
    1
    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
     
  7. DeX

    DeX Mube Codder

    Joined:
    22 Jul 2002
    Posts:
    4,152
    Likes Received:
    3
    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?
     
  8. LaughingJon

    LaughingJon What's a Dremel?

    Joined:
    12 Feb 2003
    Posts:
    282
    Likes Received:
    0
    Yes because i put an <= sign if it had just been a < it would have worked okay. I think :eyebrow: :D

    Without actually writing it and compiling it i couldnt test it tho LOL :D

    Laters
    Jon
     

Share This Page