tincho 15-04-2021, 11:13
Esta la hizo Christof, de la lista internacional de Gambas, y yo la adapte.
Fue la que obtuvo la marca de velocidad mas alta (con FAST).
Código:
'' <b>RAD Extension.</b><br>
'' It removes the spaces at the beginning and the end of
'' a <b>s</b> and if there are repeated spaces, it converts them into one.

Static Public Function Trim(s As String) As String

  Dim sOut As String

  sOut = Trim(RTrim(s))
  While InStr(sOut, "  ")
    sOut = Replace(sOut, "  ", " ")
  Wend

  Return sOut

End
Saludos.
tincho 15-04-2021, 11:11
Esta hace lo mismo que la función de Go que se llama igual.
Código:
'' <b>RAD Extension.</b><br>
'' Converts the first character of each word to upper case.
'' GO Package strings

Static Public Function Title(s As String) As String

  Dim sTmp As String
  Dim word As String
  Dim aOut As New String[]

  sTmp = Trim(RTrim(s))
  While InStr(sTmp, "  ")
    sTmp = Replace(sTmp, "  ", " ")
  Wend

  For Each word In Split(sTmp, " ")
    aOut.Add(Upper(Mid(word, 1, 1)) & Mid(Lower(word), 2))
  Next

  Return aOut.Join(" ")

End
Saludos.
tincho 15-04-2021, 11:07
Esta función la hice porque al leer datos de planos dwg, con la librería LibreDWG, algunos textos no se representaban correctamente debido a errores de codificación.
Tal vez luego pueda evolucionar a una versión mas general y amplia que abarque mas casos.
Código:
'' <b>RAD Extension.</b><br>
'' Returns a string with all its characters converted to ascii or utf-8 when bad codification ocurr.

Static Public Function Flat(s As String) As String

  Dim k As Integer = 1
  Dim q As Integer
  Dim r As Integer

  Dim uni As String
  Dim stx As New String[]
  Dim u As String
  Dim rep As String
  Dim i As Integer

  Repeat
    q = InStr(s, "\\U+", k)
    If q > 0 Then
      Inc r
      uni = String.Mid(s, q, 7)
      stx.Add(uni)
      k = q + String.Len("\\U+")
    Endif
  Until InStr(s, "\\U+", k) = 0 Or k > String.Len(s)

  For Each u In stx
    i = Val("&h" & String.Mid(u, 4, 4) & "&")
    rep = String.Chr(i)
    s = Replace(s, u, rep)
  Next

  Return s

End
Saludos.
Páginas (560):    1 458 459 460 461 462 560   
Bienvenido, Invitado
Tienes que registrarte para poder participar en nuestro foro.
Recordarme?
Miembros: 288
Último miembro: shoUsho
Temas del foro: 1,729
Mensajes del foro: 8,985
Últimos temas
Paren...WAIT !!!
Foro: Aplicaciones/Fragmentos de Código
Último mensaje por: guizans, 25-08-2025, 14:49
Respuestas: 3 - Vistas: 397
GambOS
Foro: General
Último mensaje por: guizans, 20-08-2025, 13:58
Respuestas: 0 - Vistas: 268
Gambas y Wayland
Foro: General
Último mensaje por: guizans, 20-08-2025, 13:56
Respuestas: 6 - Vistas: 542
Odio a gb.Report
Foro: General
Último mensaje por: guizans, 19-08-2025, 10:40
Respuestas: 8 - Vistas: 901
Powered By MyBB, © 2002-2025 MyBB Group.
Made with by Curves UI.