Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Trying to use string.Contains


Best Answer strent, 11 January 2013 - 07:02 AM

Contains isn't available, but the next best thing is IndexOf

Go to the full post


  • Please log in to reply
3 replies to this topic

#1 rchelicopter

rchelicopter

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationSan Diego, Ca

Posted 11 January 2013 - 04:25 AM

Is there a string.Contains alternative in .netmf.  I want to check if a string contains a certain substring

 

Like

 

string abc = 1234

 

if (abc.Contains("1234"))

{

do stuff

}



#2 strent

strent

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 11 January 2013 - 07:02 AM   Best Answer

Contains isn't available, but the next best thing is IndexOf



#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 11 January 2013 - 07:48 AM

Indeed, if IndexOf returns -1, the haystack doesn't include the needle.


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 11 January 2013 - 03:41 PM

You can always extend the String class (.netmf 4.2 makes this much easier)

 

public static bool Contains(this String _src, char _search){	for (int i = _src.Length-1; i >= 0; --i)	{		if (_src.IndexOf(_search) >= 0) { return true; }	}	return false;}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.