Jump to content

Recommended Posts

Posted

boas pessoal comecei a pouco tempo o c#.net.

e queria fazer uma coisa.

nesta string --> ola, adeus, 123.

detectar o numero de virgulas presentes nessa frase?

já tentei de várias maneiras usando o string.indexof, mas não estou a ver como é que tenho de fazer.

cumps

com calma e sem stresses

Posted

Podes fazer isso de várias maneiras:

- split por virgula -> Devolve um array em que a dimensão é o numero de virgulas + 1

- Usar uma regular expression para procurar pela virgula

- Usar o Linq para fazer um Where ou um Count ás virgulas da string

E devem haver mais umas quantas formas que não me estou a lembrar.

Matraquilhos para Android.

Gratuito na Play Store.

https://play.google.com/store/apps/details?id=pt.bca.matraquilhos

Posted

o codigo que eu tenho é este, mas o array pode ser numero indefinido?

 string[] ipsarray = new string[3];
               ipsarray = portas.Split(',');
               Ping ping = new Ping();
               PingReply resp;
           
               try
               {
                   resp = ping.Send(ipsarray[1]);
                   if (resp.Status == IPStatus.Success)
                   {
                       portas = ipsarray[1];
                   }
                   resp = ping.Send(ipsarray[2]);
                   if (resp.Status == IPStatus.Success)
                   {
                       portas = ipsarray[2];
                   }
                   resp = ping.Send(ipsarray[3]);
                   if (resp.Status == IPStatus.Success)
                   {
                       portas = ipsarray[3];
                   }
               }
                   catch (Exception e)
               {
               }

com calma e sem stresses

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.