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.
tincho 15-04-2021, 11:03
Esta función esta interesante porque permite lograr una lista de "Campos" a partir de una cadena de texto separada por espacios o tabuladores.
Código:
'' <b>RAD Extension.</b><br>
'' Fields splits the string s around each instance of one or more consecutive white space characters returning a string[] of substrings of s or an empty string[] if s contains only white space.
'' GO Package strings
Static Public Function Fields(s As String) As String[]

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

  While InStr(sTmp, "\t")
    sTmp = Replace(sTmp, "\t", " ")
  Wend

  sTmp = Trim(RTrim(s))

  While InStr(sTmp, "  ")
    sTmp = Replace(sTmp, "  ", " ")
  Wend

  For Each word In Split(sTmp, " ")
    aOut.Add(word)
  Next

  Return aOut

End
Saludos.
tincho 15-04-2021, 10:59
Esta es la versión "gambosa" de Count de Go.
Código:
'' <b>RAD Extension.</b><br>
'' Counts how much times some string apear in other

Static Public Function Count(sWhere As String, sWhich As String) As Integer

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

  Repeat
    q = InStr(sWhere, sWhich, k)
    If q > 0 Then
      Inc r
      k = q + String.Len(sWhich)
    Endif
  Until InStr(sWhere, sWhich, k) = 0 Or k > String.Len(sWhere)

  Return r

End
Saludos.
Páginas (574):    1 … 473 474 475 476 477 … 574   
Bienvenido, Invitado
Tienes que registrarte para poder participar en nuestro foro.
Recordarme?
Miembros: 317
Último miembro: Eo185sRonNh7
Temas del foro: 1,774
Mensajes del foro: 9,211
Últimos temas
El conector de alimentaci...
Foro: Hardware & IoT
Último mensaje por: tincho, 23-09-2026, 23:03
Respuestas: 3 - Vistas: 122
Me hace falta el dato de ...
Foro: Hardware & IoT
Último mensaje por: AlfredoSC, 21-09-2026, 04:13
Respuestas: 0 - Vistas: 91
Problemas con la versión ...
Foro: General
Último mensaje por: Piero71, 19-09-2026, 23:56
Respuestas: 3 - Vistas: 271
GauchoCAD vuelve a las pi...
Foro: Aplicaciones/Fragmentos de Código
Último mensaje por: tincho, 02-09-2026, 21:41
Respuestas: 21 - Vistas: 22,269
Programando con la IA
Foro: General
Último mensaje por: alberto-moyano, 02-09-2026, 18:04
Respuestas: 19 - Vistas: 9,273
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.