C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-15-2005, 05:06 PM   #1
Registered User
 
Join Date: Jul 2003
Posts: 110
String Parse.

Hi, i got the string

string word = "hello world dude";

i want to make a if that checks the string word for hello then if its in it take hello out and leave the rest


so
if("hello" in string)
strip hello from string;
Coder87C is offline   Reply With Quote
Old 08-15-2005, 05:49 PM   #2
and the Hat of Clumsiness
 
GanglyLamb's Avatar
 
Join Date: Oct 2002
Posts: 1,101
Code:
using System;

namespace ConsoleApplication1
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
	  string iCantDoMyHomeWork = "hello world dude";
	  string orAnyResearch = "";
	  orAnyResearch = iCantDoMyHomeWork.Replace("hello","");
	  Console.WriteLine("Old String: "+iCantDoMyHomeWork+"\nNew String: "+orAnyResearch);
		Console.Read();
	}
	}
}
How to replace the following white space after Hello is something you should be able to figure out yourself.
GanglyLamb is offline   Reply With Quote
Old 08-15-2005, 06:45 PM   #3
Registered User
 
Join Date: Jul 2003
Posts: 110
Lol, I wish I had a C# class. This is actually for a plugin that detects strings for macros

I got string word = "hello man";

if(word.StartsWith("hello"))

but not sure how to "Remove" it, and I see Remove but I dont think that does what I want...
Coder87C is offline   Reply With Quote
Old 08-16-2005, 02:18 AM   #4
and the Hat of Clumsiness
 
GanglyLamb's Avatar
 
Join Date: Oct 2002
Posts: 1,101
I dont know what you just said but have you tried my code, .Remove works like this
Code:
string test = "foobar";
test = test.Remove(0,3);
//test will be "bar"
So I dont know if you tried my code but it works except for the following space character which you can delete by doing this
Code:
orAnyResearch = iCantDoMyHomeWork.Replace("hello",""); 
if(orAnyResearch.StartsWith(" ")){
  orAnyResearch = orAnyResearch.Substring(1,orAnyResearch.Length-1);
}

Last edited by GanglyLamb; 08-16-2005 at 02:21 AM.
GanglyLamb is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Interpreter.c moussa C Programming 4 05-28-2008 05:59 PM
Calculator + LinkedList maro009 C++ Programming 20 05-17-2005 12:56 PM
Classes inheretance problem... NANO C++ Programming 12 12-09-2002 03:23 PM
creating class, and linking files JCK C++ Programming 12 12-08-2002 02:45 PM
Warnings, warnings, warnings? spentdome C Programming 25 05-27-2002 06:49 PM


All times are GMT -6. The time now is 06:49 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22