How to insert literal double quote without the string " becoming "?

Asked

Viewed 1,175 times

1

I work with a seeker called Lucene.net nothing more than a search engine.

I need to insert the following phrases inside the indexer separated by ;:

"bedside Lamp";"Lampshade";"table Lamp"

Double quotes are required(") because he understands that it is a sentence, so he will only recover something if the sentence is written in its entirety, as he says in that manual:

A query is Broken up into Terms and Operators. There are two types of Terms: Single Terms and Phrases.

A Single Term is a single word such as "test" or "hello".

A Phrase is a group of words surrounded by double Quotes such as "hello Dolly".

But when I use Padleft it returns a string like this:

\"bedside lamp\";\"lampshade\";\"table lamp\"

Follow the example:

PhraseIndex translation = new PhraseIndex()//Objeto que eu vou armazenar no buscador
        {
            PT_BR = "abajur;luminária",
            EN_US = "bedside lamp;lampshade;table lamp",
            ES = "pantalla;lámpara;claraboya"
        };
translation.InsertOnLucene();//Método que armazena(o modo como armazena nao afeta a pergunta, então é desnecessário)
List<String> phrases = translation.EN_US.Split(';').ToList(); //Separo todas as frases da variável EN_US dentro de uma lista
foreach(string p in translation.EN_US)
{
    translation.EN_US = translation.EN_US +p.PadLeft(p.Length+1,'"').PadRight(p.Length+1,'"') + ";"; //Aqui eu insiro uma aspas dupla no inicio e no fim de cada frase e insiro novamente dentro de EN_US separadas por ;
}

Console.WriteLine(translation.EN_US); //\"bedside lamp\";\"lampshade\";\"table lamp\" o c# insere automaticamente o " para \" sendo assim quando eu passar essa string no Lucene, ele não irá encontrar nada que tenha \"

The problem is that Lucene understands the \" as being \" and not " so much so that in the same document cited above, in the session Escaping Special Characters he quotes that one should use the \ to create these exceptions.

The question is: I can send a string to the search engine

"bedside lamp";"lampshade";"table lamp"

instead of

\"bedside lamp\";\"lampshade\";\"table lamp\"

For if I seek lamp he returns me bedside lamp 'cause you’re not looking for sentences, you’re looking for terms.

  • A very crude solution is to use replace. myVar.Replace(" , string.Empty)

  • Automatically c# converts back and inserts the \"...

  • Please mount a [mcve].

  • What you’re seeing in the Bugger is a representation of the aspone; it’s there, only the Bugger puts it \" to escape and differentiate the aspone from the string quotes C#.

  • 1

    @Marcelouchimura Wow, really ? I don’t believe rsrs... I’ll see if this is it (when we think we know something... one of these comes up)

  • @Marcelouchimura you’re right ! the problem is that I was seeing from the Bugger. I believe my problem about Ucene is at another point. Anyway you answered the question, want to create an answer? or I can close the question(I prefer that you create because it may be someone else’s doubt).

  • I am voting to close this question as out of scope because there is no problem.

  • @LINQ I’m sure you understand more than I do on the platform, but don’t you think it’s important? I think there’s going to be more people with a similar problem some time... for pure misinformation because it’s the Visual Studio platform... I don’t agree to close it but that’s okay, if it’s the ok rule.

  • @Leonardobonetti I think it is not important not, so the vote. Anyway, there is no rule about it, it is only my vote. If the community agrees the question will be closed, otherwise it stays open

  • All right @LINQ thought it was some rule, vlw.

Show 5 more comments

1 answer

2


The Visual Studio debugger, when it finds a quotation mark inside a string, escapes it because it is the usual representation of quotation marks inside strings,

inserir a descrição da imagem aqui

Only it actually exists inside the string as a quote without the backslash escape,

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.