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 (573):    1 471 472 473 474 475 573   
Bienvenido, Invitado
Tienes que registrarte para poder participar en nuestro foro.
Recordarme?
Miembros: 314
Último miembro: LKTFermin2
Temas del foro: 1,769
Mensajes del foro: 9,181
Últimos temas
Programando con la IA
Foro: General
Último mensaje por: seta43, 30-07-2026, 12:20
Respuestas: 12 - Vistas: 7,482
GauchoCAD vuelve a las pi...
Foro: Aplicaciones/Fragmentos de Código
Último mensaje por: tincho, 27-07-2026, 14:15
Respuestas: 15 - Vistas: 20,786
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.