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
  1. Home
  2. General Programming
  3. C#
  4. string

string

Scheduled Pinned Locked Moved C#
questioncsharptutorial
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.
  • S Offline
    S Offline
    simworld
    wrote on last edited by
    #1

    How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.

    J N S S 4 Replies Last reply
    0
    • S simworld

      How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.

      J Offline
      J Offline
      J 0
      wrote on last edited by
      #2

      simworld wrote:

      Is there any system defined function such as strcmp,strcpy as used in C

      To compare 2 strings, you could use the String.Compare method. To copy one string value into another, all you do is string oldValue = "OldValue"; string newValue = oldValue;

      1 Reply Last reply
      0
      • S simworld

        How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.

        N Offline
        N Offline
        NewToAspDotNet
        wrote on last edited by
        #3

        http://www.google.nl/search?hl=nl&q=c%23+compare+strings&meta=[^]

        1 Reply Last reply
        0
        • S simworld

          How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.

          S Offline
          S Offline
          Scott Dorman
          wrote on last edited by
          #4

          There are several ways you can compare strings in C#. The simplest way is to just test using equality:

          string a = "This is a test";
          string b = "This is another test";

          if (a == b) {
          // do something
          }

          However, this will do a case-sensistive, culture-sensitive compare which may not be what you want and isn't necessarily the most performant test. The closest methods to strcmp in C# are going to be the String.Compare, String.CompareOrdinal or the String.CompareTo methods. In order to copy a string, you can simply copy it. Strings in C# are immutable, so you will always get a new instance of the string:

          string a = "This is a test";
          string b = a;

          You can find all of the string methods here[^].

          Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai


          [Forum Guidelines] [Articles] [Blog]

          1 Reply Last reply
          0
          • S simworld

            How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.

            S Offline
            S Offline
            simworld
            wrote on last edited by
            #5

            thanks a lot

            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