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

613
Views
strings.Contains en switch-case GoLang

¿Es posible usar cadenas. Contiene en el caso del interruptor? algo como:

 func function(str string){ switch str { case "str1": ... case strings.Contains("test"): ... default: ... } }

Editar: es un ejemplo, ese no es el caso real para el que lo necesito. Estoy filtrando muchos resultados y quiero todos los resultados que contengan X y también tengo casos que necesito hacer coincidir por completo.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puedes hacerlo:

 package main import ( "fmt" "strings" ) func main() { str := "testString" switch { case strings.Contains(str, "test"): fmt.Println(true) default: fmt.Println(false) } }

https://go.dev/play/p/_2fMd-3kE-r

switch sin argumento es como switch true .

over 4 years ago · Santiago Trujillo Report

0

¿Por qué necesita un interruptor para esta salida booleana?

Utilice la siguiente función incorporada.

func strings.Contains(s string, substr string) bool

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
Virtual assistant