Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)
Autor
|
Tema: Extraer string entre "[" y "]" (Leído 656 veces)
|
extreme69
Desconectado
Mensajes: 166
Be BlackHat but don't forget your principles.
|
Tengo: asd = aitheoiethi[BLABLABLA]taihoithaoihtoea Y necesito "BLABLABLA" en la variable asd2. Probé con Mid, Split, Left, Right, pero en todos los casos tengo que saber las posiciones, y no sé cuantos caracteres va a tener "BLABLABLA" ni cuantos caracteres hay antes ni después. ¿Será que primero tengo que ver en que posición del string está el "[", luego hacer lo mismo con el "]" y una vez que sé las posiciones hacer un mid? ¿o hay alguna manera más fácil/rápida?
|
|
|
|
« Última modificación: 17 Septiembre 2011, 01:37 por extreme69 »
|
En línea
|
|
|
|
DarkMatrix
Desconectado
Mensajes: 125
Nuestro Limite es la Imaginacion
|
Public Function StrBetween(Cadena As String, SubCadena1 As String, Subcadena2 As String) As String Dim Pos1 As Integer, Pos2 As Integer Pos1 = InStr(UCase(Cadena), UCase(SubCadena1)) + 1 Pos2 = InStr(UCase(Cadena), UCase(Subcadena2)) If Pos1 <> 0 And Pos2 <> 0 Then StrBetween = Mid$(Cadena, Pos1, Pos2 - Pos1) End If End Function Private Sub Form_Load() Dim ASd As String Dim Asd2 As String ASd = "aitheoiethi[BLABLABLAkjhuihui]taihoithaoihtoea" Asd2 = StrBetween(ASd, "[", "]") MsgBox Asd2 End Sub Por hay tambien hay una funcion que hizo Psyke1, espero que te sirva...
|
|
|
|
« Última modificación: 17 Septiembre 2011, 01:56 por DarkMatrix »
|
En línea
|
Todo aquello que no se puede hacer, es lo que no intentamos hacer. Projecto Ani-Dimension Digital Duel Masters (Juego de cartas masivo multijugador online hecho en Visual Basic 6.0)  Desing by DarkMatrix
|
|
|
extreme69
Desconectado
Mensajes: 166
Be BlackHat but don't forget your principles.
|
Excelente, muchas gracias. 
|
|
|
|
|
En línea
|
|
|
|
BlackZeroX (Astaroth)
Wiki
Desconectado
Mensajes: 2.831
I'Love...!¡.
|
. ¿Será que primero tengo que ver en que posición del string está el "[", luego hacer lo mismo con el "]" y una vez que sé las posiciones hacer un mid? ¿o hay alguna manera más fácil/rápida?
que comes que adivinas... Cita: http://visual-coders.herobo.com/blog/?p=1 '------------------------------------------------------------------------ ' *Function : Text_Between_Words ' *Author : *PsYkE1* ' *Mail : vbpsyke1@mixmail.com ' *Date : 10/4/10 ' *Purpose : It returns the text wich is between two words ' *Recommended Websites : ' http://foro.rthacker.net/ ' http://InfrAngeluX.Sytes.Net/ '------------------------------------------------------------------------ Option Explicit Public Function Text_Between_Words(ByVal sTextToAnalyze As String, ByVal sStartWord As String, ByVal sEndWord As String) As String Dim iPosition1 As Integer Dim iPosition2 As Integer Dim iStart As Integer iPosition1 = InStr(sTextToAnalyze, sStartWord) If CBool(iPosition1) Then iStart = iPosition1 + Len(sStartWord) iPosition2 = InStr(iStart, sTextToAnalyze, sEndWord) If CBool(iPosition2) Then Text_Between_Words = Mid$(sTextToAnalyze, iStart, iPosition2 - iStart) End If End If End Function Debug.Print Text_Between_Words("El contexto es el ámbito de referencia de un texto. ¿Qué entiendo por ámbito de referencia?.", "referencia", "referencia") Dulces Lunas!¡.
|
|
|
|
« Última modificación: 17 Septiembre 2011, 04:07 por BlackZeroX▓▓▒▒░░ »
|
En línea
|
|
|
|
|
seba123neo
|
Private Sub Form_Load() MsgBox TextoEntreMedio("aitheoiethi[BLABLABLA]taihoithaoihtoea", "[", "]") End Sub Private Function TextoEntreMedio(Texto As String, Palabra1 As String, Palabra2 As String) TextoEntreMedio = Left$(Mid$(Texto, InStr(Texto, Palabra1) + Len(Palabra1)), InStr(Mid$(Texto, InStr(Texto, Palabra1) + Len(Palabra1)), Palabra2) - 1) End Function
|
|
|
|
|
En línea
|
Mucha gente, especialmente la ignorante desea castigarte por decir la verdad, por ser correcto, por ser tú. Nunca te disculpes por ser correcto, o por estar años delante de tu tiempo. Si estas en lo cierto, y lo sabes, que hable tu razón. Incluso si eres una minoria de uno solo, la verdad sigue siendo la verdad. M. Gandhi
|
|
|
BlackZeroX (Astaroth)
Wiki
Desconectado
Mensajes: 2.831
I'Love...!¡.
|
Private Sub Form_Load() MsgBox TextoEntreMedio("aitheoiethi[BLABLABLA]taihoithaoihtoea", "(", "]") End Sub Dulces Lunas!¡.
|
|
|
|
|
En línea
|
|
|
|
Psyke1
Wiki
Desconectado
Mensajes: 1.005
|
Un poco mejorada: Option Explicit Public Static Function TextBetweenWords$(ByRef sText$, ByVal sWord1$, ByVal sWord2$) Dim lPos1&, lPos2&, lStart& If LenB(sText) Then lPos1 = InStrB(1, sText, sWord1, vbBinaryCompare) If lPos1 Then lStart = lPos1 + LenB(sWord1) lPos2 = InStrB(lStart, sText, sWord2, vbBinaryCompare) If lPos2 Then TextBetweenWords = MidB$(sText, lStart, lPos2 - lStart) End If End If End If End Function Private Sub Form_Load() Debug.Print TextBetweenWords("qwertysdfcv [raul338 es feo] prueba", "[", "]") End Sub Devuelve: raul338 es feo
Y con RegExp: \[([^\[]+)\] DoEvents! 
|
|
|
|
« Última modificación: 17 Septiembre 2011, 16:53 por Psyke1 »
|
En línea
|
|
|
|
|
| Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Que Diferencia hay entre versiones "Enterprise" y "Standard" del Soft. Deep Free
Software
|
Ad0nis
|
0
|
943
|
19 Noviembre 2005, 22:59
por Ad0nis
|
|
|
De donde puedo descargar utilidades: "Formas", "Estilos", "Motivos", D
Diseño Gráfico
|
Ad0nis
|
2
|
1,395
|
2 Septiembre 2006, 15:48
por Ad0nis
|
|
|
[Ayuda] modificar "start page" en "internet explorer" con "batch"
Scripting
|
taton
|
7
|
4,227
|
20 Septiembre 2006, 01:45
por taton
|
|
|
¿Cuál es la diferencia entre un proxy "anonymous" y uno "high anonymity"?
Hacking Básico
|
USUARIO_DE_SOFTWARE_LIBRE
|
1
|
1,172
|
8 Diciembre 2006, 02:46
por soplo
|
|
|
Recuperando los boot de vista y XP. Que diferencia hay entre "Legacy" y "ntldr"
Windows
|
rockeropasiempre
|
2
|
2,284
|
8 Noviembre 2008, 14:51
por rockeropasiempre
|
|