elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  como trabajar con string que contenga ""
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: como trabajar con string que contenga ""  (Leído 3,106 veces)
+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
como trabajar con string que contenga ""
« en: 20 Mayo 2016, 01:39 am »

me explico tengo esta cadena

"To be or not to be," quoth the Bard, "that
is the question".

ahora tengo que trabajar sobre esa cadena y al pasarlo como parametro me sale error, bueno es obvio ya que

quoth the Bard      no se encuentra entre comillas


como se soluciona ?


En línea

engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: como trabajar con string que contenga ""
« Respuesta #1 en: 20 Mayo 2016, 01:43 am »

no estoy seguro si en java, pero normalmente cundo quieres incluir comillas o caracteres especiales lo escapas (le colocas un \ previo para que se asuma literal, ejemplo "el dijo: \"hola mundo\"")


En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
AlbertoBSD
Programador y
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.696


🏴 Libertad!!!!!


Ver Perfil WWW
Re: como trabajar con string que contenga ""
« Respuesta #2 en: 20 Mayo 2016, 01:47 am »

Es correcto con \"

Mas info es http://stackoverflow.com/questions/1367322/what-are-all-the-escape-characters-in-java
En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: como trabajar con string que contenga ""
« Respuesta #3 en: 20 Mayo 2016, 01:49 am »

tengo que trabajar sobre las comillas:

Sample Input

"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"

Sample Output

``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''

En línea

AlbertoBSD
Programador y
Moderador Global
***
Desconectado Desconectado

Mensajes: 3.696


🏴 Libertad!!!!!


Ver Perfil WWW
Re: como trabajar con string que contenga ""
« Respuesta #4 en: 20 Mayo 2016, 01:52 am »

Cual es el codigo que las lee y cual es que las manda a pantalla?
En línea

+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: como trabajar con string que contenga ""
« Respuesta #5 en: 20 Mayo 2016, 01:55 am »

bueno este es el problema que quiero resolver

TeX Quotes

TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use `` and " to delimit quotations, rather than the mundane " which is what is provided by most keyboards. Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote ` and a right-single-quote '. Check your keyboard now to locate the left-single-quote key ` (sometimes called the ``backquote key") and the right-single-quote key ' (sometimes called the ``apostrophe" or just ``quote"). Be careful not to confuse the left-single-quote ` with the ``backslash" key \. TeX lets the user type two left-single-quotes `` to create a left-double-quote `` and two right-single-quotes '' to create a right-double-quote ''. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote ".

If the source contained

"To be or not to be," quoth the bard, "that is the question."

then the typeset document produced by TeX would not contain the desired form:

``To be or not to be," quoth the bard, ``that is the question."

In order to produce the desired form, the source file must contain the sequence:

``To be or not to be,'' quoth the bard, ``that is the question.''

You are to write a program which converts text containing double-quote (") characters into text that is identical except that double-quotes have been replaced by the two-character sequences required by TeX for delimiting quotations with oriented double-quotes. The double-quote (") characters should be replaced appropriately by either `` if the " opens a quotation and by '' if the " closes a quotation. Notice that the question of nested quotations does not arise: The first " must be replaced by ``, the next by '', the next by ``, the next by '', the next by ``, the next by '', and so on.

Input and Output

Input will consist of several lines of text containing an even number of double-quote (") characters. Input is ended with an end-of-file character. The text must be output exactly as it was input except that:

    the first " in each pair is replaced by two ` characters: `` and
    the second " in each pair is replaced by two ' characters: ''.

Sample Input

"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"

Sample Output

``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''




mi codigo es el siguiente aunque no esta bien creo

Código
  1. public class TexQuotes {
  2. public String tes(String textoMain){
  3.    char caracter=' ';
  4.    int contador=0;
  5.    String answer="";
  6.    for (int i = 0; i < textoMain.length(); i++) {
  7.        caracter=textoMain.charAt(i);
  8.  
  9.        if(caracter==34){
  10.            contador=1;
  11.            if(contador==1){
  12.            answer=answer+96;
  13.            }else{
  14.            answer=answer+caracter;
  15.            contador=0;
  16.            }
  17.        }else{
  18.        answer=answer+caracter;
  19.        }
  20.    }
  21.    System.out.println(answer);
  22.    return answer;
  23. }    
  24. public static void main(String args[]){
  25.    TexQuotes t=new TexQuotes();
  26.    t.tes("To be or not to be," quoth the Bard, "that is the question".);
  27. }
  28. }
  29.  
En línea

engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: como trabajar con string que contenga ""
« Respuesta #6 en: 20 Mayo 2016, 02:00 am »

algo que creo es que tienes un error XD colocan el quote de cerrado como comilla simple, pero es acento es decir

``aquí inicia, pero aquí termina´´
``aquí inicia y esto es algo diferente''

Código
  1. t.tes("\"To be or not to be,\" quoth the Bard, \"that is the question\".");
En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: como trabajar con string que contenga ""
« Respuesta #7 en: 20 Mayo 2016, 02:26 am »

Citar
``aquí inicia, pero aquí termina´´
``aquí inicia y esto es algo diferente''

te refieres al input y output???
En línea

engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: como trabajar con string que contenga ""
« Respuesta #8 en: 20 Mayo 2016, 02:43 am »

las comillas

el texto está
Citar
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''

pero las smart quotes son (el mismo texto lo dice)
Citar
``To be or not to be,´´ quoth the Bard, ``that
is the question´´.
The programming contestant replied: ``I must disagree.
To `C´ or not to `C´, that is The Question!´´
En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
+ 1 Oculto(s)

Desconectado Desconectado

Mensajes: 298


un defecto se puede convertir en una virtud


Ver Perfil WWW
Re: como trabajar con string que contenga ""
« Respuesta #9 en: 20 Mayo 2016, 04:31 am »

muchas gracias por la ayuda me sirvio de mucho
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines