Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Translate this method to c++;

Translate this method to c++;

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharphelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bo Hunter
    wrote on last edited by
    #1

    Can some one help me write this in c++; I am using csharp but i want this in native code;

    public static bool Contains( ref string[][] lookupTable, string value, bool ignoreCase )
    	{
    	int i = value.Length;
    	if ( i <= 0 || i - 1 >= (int)lookupTable.Length )
    	{
    		return false;
    	}
    	string[] strs = lookupTable[i - 1];
    	if ( strs == null )
    	{
    		return false;
    	}
    	else
    	{
    		return Contains( ref strs, value, ignoreCase );
    	}
    }
    

    Thank You Bo Hunter

    H J J 3 Replies Last reply
    0
    • B Bo Hunter

      Can some one help me write this in c++; I am using csharp but i want this in native code;

      public static bool Contains( ref string[][] lookupTable, string value, bool ignoreCase )
      	{
      	int i = value.Length;
      	if ( i <= 0 || i - 1 >= (int)lookupTable.Length )
      	{
      		return false;
      	}
      	string[] strs = lookupTable[i - 1];
      	if ( strs == null )
      	{
      		return false;
      	}
      	else
      	{
      		return Contains( ref strs, value, ignoreCase );
      	}
      }
      

      Thank You Bo Hunter

      H Offline
      H Offline
      HJo
      wrote on last edited by
      #2

      This function does not compile in C# (bad parameter in recursive call), and as far as I can see it doesn't do anything useful (it always return false). If you fix that, I might be able to help you.

      B 1 Reply Last reply
      0
      • B Bo Hunter

        Can some one help me write this in c++; I am using csharp but i want this in native code;

        public static bool Contains( ref string[][] lookupTable, string value, bool ignoreCase )
        	{
        	int i = value.Length;
        	if ( i <= 0 || i - 1 >= (int)lookupTable.Length )
        	{
        		return false;
        	}
        	string[] strs = lookupTable[i - 1];
        	if ( strs == null )
        	{
        		return false;
        	}
        	else
        	{
        		return Contains( ref strs, value, ignoreCase );
        	}
        }
        

        Thank You Bo Hunter

        J Offline
        J Offline
        Jonas Larsson
        wrote on last edited by
        #3

        Assuming you have a function called Contains that takes an array of strings, you could write it like this: (note: I havent compiled or tested it)

        typedef std::vector<std::string> string_row;
        typedef std::vector<string_row> string_matrix;
        bool Contains (const string_row& lookupTable, const std::string& value, bool ignoreCase); 
        
        bool Contains (const string_matrix& lookupTable, const std::string& value, bool ignoreCase)
        {
        	int i = value.length();
        	if ( i <= 0 || i-1 >= lookupTable.size() )
        		return false;
        
        	const string_row& strs = lookupTable[i-1];
                // not sure what you want here (do you have null ref's in c#???)
        	if (strs.size() == 0) 
        		return false;
        	else
        		return Contains(strs, value, ignoreCase);		
        
        }
        

        “Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002

        1 Reply Last reply
        0
        • H HJo

          This function does not compile in C# (bad parameter in recursive call), and as far as I can see it doesn't do anything useful (it always return false). If you fix that, I might be able to help you.

          B Offline
          B Offline
          Bo Hunter
          wrote on last edited by
          #4

          Well this probaly want compile by it self but I just need some help writing this in C++. if you would look closely at this you would see that this is not a recursive call. The other Contians method takes a single deminsion array of strings this one takes two deminsion array of strings. I just thought if I could get help with this one I could do the rest myself. I dont like to see people to throw up a bunch of code and ask someone to translate it for them. I would like to learn to do it myself. Thank You Bo Hunter

          1 Reply Last reply
          0
          • B Bo Hunter

            Can some one help me write this in c++; I am using csharp but i want this in native code;

            public static bool Contains( ref string[][] lookupTable, string value, bool ignoreCase )
            	{
            	int i = value.Length;
            	if ( i <= 0 || i - 1 >= (int)lookupTable.Length )
            	{
            		return false;
            	}
            	string[] strs = lookupTable[i - 1];
            	if ( strs == null )
            	{
            		return false;
            	}
            	else
            	{
            		return Contains( ref strs, value, ignoreCase );
            	}
            }
            

            Thank You Bo Hunter

            J Offline
            J Offline
            JWood
            wrote on last edited by
            #5

            This looks like a homework assignment for a CS course.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups