Results 1 to 4 of 4

Thread: I'm Back! - Need Help w/ String Comparison

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    102

    Cool I'm Back! - Need Help w/ String Comparison

    Hey Everybody!

    Its been a long time since ive been at these forums, but the time of return has finally arrived. I just started doing C++ very recently (in fact, about 4.5 days ago) and I was looking to do string comparison as part of a little beginner project.

    My question is, how can I declare two string and determine if they are equal?

    Also, how can I copy a segment of a string, anywhere in the string?

    Any help would be greatly appreciated!

    Thanks

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    To compare two strings, you use "strcmp" providing it two strings to compare. I'll return 0 if both are same, <0 if first string is less than the second string, >0 if first string is greater than the second string.

    PHP Code:
    #include <iostream.h>
    #include <string>
    void main()
    {
    char string1[20] = "Hello";
    char string2[20] = "Boy";
    if (
    strcmp(string1,string2) == 0)
    {
    cout<<"Both strings are same";

    To get some specific characters from a string, check out this thread:
    http://www.vbforums.com/showthread.p...hreadid=115560
    Baaaaaaaaah

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    102

    Cool Nice!

    Awesome!

    Thank you very much!

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You welcome
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width