Jump to content

Retirar string de outra string


Nuno

Recommended Posts

Precisava de ajuda para saber como retirar na string abaixo tudo o que está entre "aAVa" e "%"

%%ñ%l4aAVaTExto a retirar%K@0 óøóø%%%Ùñ%l,aAVaA TExto a retirar2%%%$ñ%l(aAVaA1%%%ñ%l,aAVaA 6,51%6²K@0 ×vî×vî%%×%l,aAVaTExto a retirar3%K@0 óøóøK@0 £×î£×î%%Ê×%l,aAVaAP.V.P.%K@0 óøóøK@0 ×5î×5î%%×%l(aAVaAUd%K@0 óøóøK@0 W×®îW×®î%%j×%l,aAVaAImporte%K@0 óøóø%%{%l(

Obrigado

cumps

Link to comment
Share on other sites

Atenção que apenas é "aAVa" no início. Todos os outros são "aAVaA".

De qualquer forma, podes moldar os resultados.

Deixo-te duas sugestões: uma sapateira:

Dim Resultados As New List(Of String)
       Dim S As String = "%%ñ%l4aAVaTExto a retirar%K@0 óøóø%%%Ùñ%l,aAVaA TExto a retirar2%%%$ñ%l(aAVaA1%%%ñ%l,aAVaA 6,51%6²K@0 ×vî×vî%%×%l,aAVaTExto a retirar3%K@0 óøóøK@0 £×î£×î%%Ê×%l,aAVaAP.V.P.%K@0 óøóøK@0 ×5î×5î%%×%l(aAVaAUd%K@0 óøóøK@0 W×®îW×®î%%j×%l,aAVaAImporte%K@0 óøóø%%{%l("
       Dim Blocos As String() = S.Split({"aAVa"}, StringSplitOptions.RemoveEmptyEntries)
       For Each B As String In Blocos
           Dim tmp As String = B.Substring(0, B.IndexOf("%")).Trim
           If Not tmp = String.Empty Then Resultados.Add(tmp.TrimStart("A"))
       Next

E outra mais bonita, com uma expressão regular:

Dim Resultados As New List(Of String)
       Dim S As String = "%%ñ%l4aAVaTExto a retirar%K@0 óøóø%%%Ùñ%l,aAVaA TExto a retirar2%%%$ñ%l(aAVaA1%%%ñ%l,aAVaA 6,51%6²K@0 ×vî×vî%%×%l,aAVaTExto a retirar3%K@0 óøóøK@0 £×î£×î%%Ê×%l,aAVaAP.V.P.%K@0 óøóøK@0 ×5î×5î%%×%l(aAVaAUd%K@0 óøóøK@0 W×®îW×®î%%j×%l,aAVaAImporte%K@0 óøóø%%{%l("
       Dim regex As New Regex("(aAVaA|aAVa)(?<1>.*?)%")
       For Each Regex_Resultados As Match In regex.Matches(S)
           Resultados.Add(Regex_Resultados.Result("$1").Trim)
       Next

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.