Jump to content

Verificar existencia de uma substring numa string


Nuno

Recommended Posts

boas na seguinte string queria verificar a existencia da palavra "aAVa"

testei com

 if linha.contains("aAVa")

mas nada feito.

String:

linha= %%ñ%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(

Link to comment
Share on other sites

Estás a fazer alguma coisa errada, porque isso tem de funcionar.

Dim linha 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("
MsgBox(linha.Contains("aAVa"))

Devolverá TRUE, que indica que existe

Alternativamente podes testar se o índice de uma sub-string é diferente de -1 (ou seja, existe algures), assim:

MsgBox(linha.IndexOf("aAVa") <> -1)

Devolverá TRUE, que indica que existe.

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.