elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [APORTE] ReadIni Memoria
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] ReadIni Memoria  (Leído 2,430 veces)
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
[APORTE] ReadIni Memoria
« en: 1 Julio 2014, 20:08 pm »

Bueno, estaba trabajando con archivos en memoria, y no quería guardarlos en directorios temporales o cosas así, así que hice una función que simula a GetPrivateProfileString.

PD: solamente hice en modo lectura, ya que des-en-crip-to un archivo y ni me interesa modifcarlo desde ahí.

Código
  1. Public Function MiseryReadKey(Cadena As String, Section As String, Key As String) As String
  2. 'BreakLine = Enter o ;
  3.  
  4. Dim FirstPos As Long, LastPos As Long, FitPos As Long
  5. Dim FinalStr As String
  6.  
  7. Section = UCase(Section)
  8. Key = UCase(Key)
  9.  
  10. '[Section]
  11. FirstPos = InStr(1, UCase(Cadena), "[" & Section & "]")
  12.  
  13. If FirstPos < 1 Then
  14.    MiseryReadKey = ""
  15.    Exit Function
  16. End If
  17.  
  18. FirstPos = FirstPos + Len("[" & Section & "]")
  19.  
  20. LastPos = InStr(FirstPos, UCase(Cadena), "[") - 1
  21.  
  22. 'Patch, si está al final no ván a haber más "["
  23. If LastPos < 1 Then
  24.    LastPos = Len(Cadena) + 1
  25. End If
  26.  
  27. FinalStr = Mid(Cadena, FirstPos, LastPos - FirstPos)
  28.  
  29. 'Key
  30. FirstPos = InStr(1, UCase(FinalStr), Key)
  31.  
  32. If FirstPos < 1 Then
  33.    MiseryReadKey = ""
  34.    Exit Function
  35. End If
  36.  
  37. LastPos = InStr(FirstPos, FinalStr, Chr(13)) - 1 'Patch 07/07/2014
  38.  
  39. 'Patch, lo mismo acá, no ván a haber más enters si lée el último
  40. If LastPos < 1 Then
  41.    LastPos = Len(FinalStr) + 1
  42. End If
  43.  
  44. 'Hay un comentario
  45. FitPos = InStr(FirstPos, FinalStr, ";")
  46. If FitPos > 0 Then
  47.    If FitPos < LastPos Then
  48.        LastPos = FitPos - 1
  49.    End If
  50. End If
  51.  
  52. '=
  53. FirstPos = InStr(FirstPos, FinalStr, "=")
  54.  
  55. If FirstPos < 1 Then
  56.    MiseryReadKey = ""
  57.    Exit Function
  58. End If
  59.  
  60. MiseryReadKey = Trim(Mid(FinalStr, FirstPos + 1, LastPos - FirstPos))
  61. End Function
  62.  

Código
  1. MsgBox MiseryReadKey(txtFile.Text, "NUMERO1", "Val1")
  2.  

El FitPos es para el enter o ;

Archivo:
Código
  1. [NUMERO1]
  2. Val1=333 ;asd
  3. Val2=666;asd
  4.  

Saludos!


« Última modificación: 7 Julio 2014, 22:04 pm por Miseryk » En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
79137913


Desconectado Desconectado

Mensajes: 1.169


4 Esquinas


Ver Perfil WWW
Re: [APORTE] ReadIni Memoria
« Respuesta #1 en: 2 Julio 2014, 17:40 pm »

HOLA!!!

Soporta Unicode?

P.D: muy buen aporte!

GRACIAS POR LEER!!!


En línea

"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

 79137913                          *Shadow Scouts Team*
engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: [APORTE] ReadIni Memoria
« Respuesta #2 en: 2 Julio 2014, 19:57 pm »

des-en-crip-to

descifro*

:P el foro está forzado para que la gente use la palabra correcta XD
En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: [APORTE] ReadIni Memoria
« Respuesta #3 en: 3 Julio 2014, 20:55 pm »

HOLA!!!

Soporta Unicode?

P.D: muy buen aporte!

GRACIAS POR LEER!!!

Gracias (Y)

No, solamente soporta texto en string, textbox y cosas así, los cuales usan ANSI, estoy en lo correcto o estoy hablando boludeces?

descifro*

:P el foro está forzado para que la gente use la palabra correcta XD

Ah, no sabía, pensé que era para que google u otras páginas no tomen a foro.elhacker como spam o con virus.

Edit:
Aunque busca hasta enters o ; y lo guarda a string, desconozco si realmente guarda bien los bytes ahí, pero debería probarlo.
« Última modificación: 3 Julio 2014, 20:57 pm por Miseryk » En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
79137913


Desconectado Desconectado

Mensajes: 1.169


4 Esquinas


Ver Perfil WWW
Re: [APORTE] ReadIni Memoria
« Respuesta #4 en: 4 Julio 2014, 18:39 pm »

HOLA!!!

Me imagino, supongo que no debe soportar, intenta meter un archivo binario en memoria y volver a volcarlo, si funciona soporta unicode sino no.

GRACIAS POR LEER!!!
En línea

"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

 79137913                          *Shadow Scouts Team*
Miseryk

Desconectado Desconectado

Mensajes: 225


SI.NU.SA U.GU.DE (2NE1 - D-Unit)


Ver Perfil
Re: [APORTE] ReadIni Memoria
« Respuesta #5 en: 8 Julio 2014, 22:21 pm »

Patch:

Código
  1. Public Function MiseryReadKey(Cadena As String, Section As String, key As String) As String
  2. 'BreakLine = Enter o ;
  3.  
  4. Dim FirstPos As Long, LastPos As Long, FitPos As Long
  5. Dim FinalStr As String
  6.  
  7. Section = UCase(Section)
  8. key = UCase(key & "=") 'Patch 08/07/2014
  9.  
  10. '[Section]
  11. FirstPos = InStr(1, UCase(Cadena), "[" & Section & "]")
  12.  
  13. If FirstPos < 1 Then
  14.    MiseryReadKey = ""
  15.    Exit Function
  16. End If
  17.  
  18. FirstPos = FirstPos + Len("[" & Section & "]")
  19.  
  20. LastPos = InStr(FirstPos, UCase(Cadena), "[") - 1
  21.  
  22. 'Patch, si está al final no ván a haber más "["
  23. If LastPos < 1 Then
  24.    LastPos = Len(Cadena) + 1
  25. End If
  26.  
  27. FinalStr = mid(Cadena, FirstPos, LastPos - FirstPos)
  28.  
  29. 'Key
  30. FirstPos = InStr(1, UCase(FinalStr), key)
  31.  
  32. If FirstPos < 1 Then
  33.    MiseryReadKey = ""
  34.    Exit Function
  35. End If
  36.  
  37. LastPos = InStr(FirstPos, FinalStr, Chr(13)) - 1 'Patch 07/07/2014
  38.  
  39. 'Patch, lo mismo acá, no ván a haber más enters si lée el último
  40. If LastPos < 1 Then
  41.    LastPos = Len(FinalStr) + 1
  42. End If
  43.  
  44. 'Hay un comentario
  45. FitPos = InStr(FirstPos, FinalStr, ";")
  46. If FitPos > 0 Then
  47.    If FitPos < LastPos Then
  48.        LastPos = FitPos - 1
  49.    End If
  50. End If
  51.  
  52. '=
  53. FirstPos = InStr(FirstPos, FinalStr, "=")
  54.  
  55. If FirstPos < 1 Then
  56.    MiseryReadKey = ""
  57.    Exit Function
  58. End If
  59.  
  60. MiseryReadKey = Trim(mid(FinalStr, FirstPos + 1, LastPos - FirstPos))
  61. End Function
  62.  
En línea

Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It’s never too late to change our luck
So, don’t let them steal your light
Don’t let them break your stride
There is light on the other side
And you’ll see all the raindrops falling behind
Make it out tonight
it’s a revolution

CL!!!
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines