Jump to content
Nuno

Retirar string de outra string

Recommended Posts

Nuno

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

Share this post


Link to post
Share on other sites
ribeiro55

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"

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.