Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
Subcadena de caracteres intermedios en Java

Quiero subcadenar el valor "o a p" en dos variables de cadena como esta

 o p

Traté de subcadenar este código, pero parece que no funciona.

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

esto vuelve "a p"

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto:

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

0

Si quieres hacerlo sin split (que es más fácil, pero en fin):

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

El punto que te falta es que indexOf devuelve la posición del inicio de la cadena de búsqueda; si desea lo que viene después, debe aumentar el índice por la longitud de esa cadena de búsqueda.

over 4 years ago · Santiago Trujillo Report

0

 String arr[] = rt.split("to"); //arr[0] is the 1st part and arr[1] second.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!