Article View: es.comp.lenguajes.java
Article #707Re: OBTENER CADENA DE CARACTERES REPETIDOS
From: Ricardo Palomares Martinez
Date: Sun, 21 Jan 2007 22:37
Date: Sun, 21 Jan 2007 22:37
34 lines
1792 bytes
1792 bytes
FF escribió:
> Hola a todos,
>
> ¿cómo puedo obtener un String que contenga x caracteres repetidos? Por
> ejemplo un String con 5 espacios.
>
> Perdón por la tontería de pregunta, pero estoy muuuy verde en Java.
Pues la verdad es que he estado buscando y no he visto ningún método
en Character ni en String que haga lo que quieres. Lo más efectivo
quizá sea algo así:
// l es la longitud que se quiere replicar
int l = 10;
// c es el carácter que se quiere repetir
char c = '=';
StringBuilder sb = new StringBuilder(l);
for(int i = 0; i < l; i++) {
sb.append(c);
}
String suCadenaGracias = sb.toString();
Y en suCadenaGracias tendrás el string que quieres.
Saludos.
--
If it's true that we are here to help others,
then what exactly are the OTHERS here for?
Technical Details
Message-ID:
<7j6d84-vui.ln1@Father.family>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.newsland.it!aioe.org!Father.family!newsReferences:
<eorksj$4bl$1@hefestos.uned.es>Show Full Headers
Complete Article Headers
X-Google-Thread: 1116f3,ebe279053063434b X-Google-Attributes: gid1116f3,public X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.newsland.it!aioe.org!Father.family!news From: Ricardo Palomares Martinez <rpm.PUBLI@iespana.es> Newsgroups: es.comp.lenguajes.java Subject: Re: OBTENER CADENA DE CARACTERES REPETIDOS Date: Sun, 21 Jan 2007 23:37:58 +0100 Organization: Hogar, dulce hogar Lines: 34 Message-ID: <7j6d84-vui.ln1@Father.family> References: <eorksj$4bl$1@hefestos.uned.es> NNTP-Posting-Host: bO6qkE19wY1WwGsuJE7Aow.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.8.1.2pre) Gecko/20070111 SeaMonkey/1.1 Mnenhy/0.7.4.0