-
Need Help Please in counting a String object in Array
I need help in counting how many time "and" is in the Array. I can find its location count all but not just "and". Help would be great. Thanks!!!!
#using <mscorlib.dll>
#using <System.dll>
#include <algorithm>
#using <System.Windows.Forms.dll>
using namespace System;// Array class
using namespace System::Collections;
using namespace System::Windows::Forms;
// Object class contains a ToString method:
void showSingleManagedArray(Object * arr[], String * name)
{
// Begin with an empty String
String * str = S"";
// Add to the existing String (str)
// array value to the Concat method
// assigning the result back to str.
for (int i=0; i<arr->Length; i++)
if (arr[i] != 0) // check for null reference
str = String::Concat(str, arr[i]->ToString(), S"\n");
// Display the array elements that are stored in the String:
MessageBox::Show(str, name);
}
int __stdcall WinMain()
{
String * strArray[] = new String * [4];
strArray[0] = S"This was";
strArray[1] = S"very challenging";
strArray[2] = S"and";
strArray[3] = S"grey matter intensive";
showSingleManagedArray(strArray, S"Original String Array");
// invoke the Contains method:
if (strArray->Contains(S"and"))
MessageBox::Show(
S" and ", S"Found");
//if object not found
else
MessageBox::Show(
S"and not found", S"Not Found");
int index = Array::IndexOf(strArray, S"and");
if (index != -1)
MessageBox::Show(
index.ToString(),
S" and was found at index!"
);
MessageBox::Show(
strArray->Count.ToString(),
S"Showing Count"
);
return(0);
}
Similar Threads
-
By Marcos in forum VB Classic
Replies: 3
Last Post: 01-25-2006, 11:18 AM
-
By mdengler in forum ASP.NET
Replies: 0
Last Post: 11-26-2002, 02:32 PM
-
By JULDUZ in forum ASP.NET
Replies: 0
Last Post: 08-29-2002, 09:40 AM
-
By Simon sjonesATwebpage-marketing.com in forum .NET
Replies: 2
Last Post: 06-05-2002, 01:11 PM
-
By Julian Milano in forum VB Classic
Replies: 2
Last Post: 08-11-2000, 12:11 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks