Thread: String Parse.

  1. #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;

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    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.

  3. #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...

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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