Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Substring a middle characters in java

I want to substring the value "o to p" in to two string variables like this

o
p

I tried to substring this code but it doesn't seems to work.

String x = rt.substring(rt.indexOf(" to ")+1);

this returns "to p"

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Try this:

String[] output = "o to p".split(" to ");
String var1 = output[0]; // "o"
String var2 = output[1]; // "p"
over 4 years ago · Santiago Trujillo Relatório

0

If you want to do it without split (which is easier, but anyway):

int pos = rt.indexOf(" to ");
String var1 = rt.substring(0, pos);
String var2 = rt.substring(pos + " to ".length());

The point you are missing is that indexOf returns the position of the start of the search string; if you want what comes after it, you need to increase the index by the length of that search string.

over 4 years ago · Santiago Trujillo Relatório

0

       String arr[] = rt.split("to");
        //arr[0] is the 1st part and arr[1] second.
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda