473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

if(word_a != word_b) then ...

if(word_a != word_b) then .... this (i.e., comparing
strings) doesn't seem to be allowed in C# - or is there
a way?

Please respond,
thank you,
Adrian.
Nov 16 '05 #1
11 1119
I'm not sure if I understood your question. But this works for me:

string s1 = "Hello";
string s2 = "Hello";
Console.WriteLine("Are strings different? {0}",
(s1 != s2) ? "Yes!" : "No!");

kind regards,

matthias

--

I love deadlines. I like the whooshing sound they make as they fly by.
[Douglas Adams]

Adrian wrote:
if(word_a != word_b) then .... this (i.e., comparing
strings) doesn't seem to be allowed in C# - or is there
a way?

Please respond,
thank you,
Adrian.

Nov 16 '05 #2
Hi,

It does work of course,

Post an example with your problem and with the EXACT contents of the
strings

maybe you have them with different cases, do this:

if( word_a.ToLower() != word_b.ToLower() )
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Adrian" <aa@aa.aa> wrote in message
news:75***************************@freeler.nl...
if(word_a != word_b) then .... this (i.e., comparing
strings) doesn't seem to be allowed in C# - or is there
a way?

Please respond,
thank you,
Adrian.

Nov 16 '05 #3

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

It does work of course,

Post an example with your problem and with the EXACT contents of the
strings


private void Form1_Load(object sender, System.EventArgs e)

{

if("monkey" < "donkey")

panel1.Text = "Monkey is smaller than donkey";

else

panel1.Text = "Monkey is not smaller than donkey";

}


Nov 16 '05 #4
Equality and inequality work. You're probably thinking of the
operators < and > (and <= and >=). These don't work on
strings in C# - you need to use the CompareTo method.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #5
You can't use "<" and ">" on string, but you asked if you could use "!=";
that is possible:

if("monkey" != "donkey")
panel1.Text = "Monkey is not donkey";
else
panel1.Text = "Monkey is donkey";

If you want to be able to say monkey < donkey you could use an enum like
this:

public enum Animals
{
Monkey = 0,
Donkey = 1
}

if(Animals.Monkey<Animals.Donkey)
{
//do something
}
else
{
//do something else
}

"Adrian" <no@spam.pls> wrote in message
news:52************************@freeler.nl...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

It does work of course,

Post an example with your problem and with the EXACT contents of the
strings


private void Form1_Load(object sender, System.EventArgs e)

{

if("monkey" < "donkey")

panel1.Text = "Monkey is smaller than donkey";

else

panel1.Text = "Monkey is not smaller than donkey";

}


Nov 16 '05 #6
Adrian <no@spam.pls> wrote:
It does work of course,

Post an example with your problem and with the EXACT contents of the
strings


private void Form1_Load(object sender, System.EventArgs e)

{

if("monkey" < "donkey")

panel1.Text = "Monkey is smaller than donkey";

else

panel1.Text = "Monkey is not smaller than donkey";

}


That's an entirely different matter. != is defined for strings, but <
isn't. Use String.Compare or String.CompareOrdinal to compare two
strings. (Or String.CompareTo...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
You can't use "<" and ">" on string, but you asked if you could use "!=";
that is possible:

if("monkey" != "donkey")
panel1.Text = "Monkey is not donkey";
else
panel1.Text = "Monkey is donkey";

If you want to be able to say monkey < donkey you could use an enum like
this:

public enum Animals
{
Monkey = 0,
Donkey = 1
}

if(Animals.Monkey<Animals.Donkey)
{
//do something
}
else
{
//do something else
}

"Adrian" <no@spam.pls> wrote in message
news:52************************@freeler.nl...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>

wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

It does work of course,

Post an example with your problem and with the EXACT contents of the
strings


private void Form1_Load(object sender, System.EventArgs e)

{

if("monkey" < "donkey")

panel1.Text = "Monkey is smaller than donkey";

else

panel1.Text = "Monkey is not smaller than donkey";

}



Nov 16 '05 #8
"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
You can't use "<" and ">" on string, but you asked if you could use "!=";
that is possible:

Apologies for the messy question.
Working until late last night.

My problem is that I need to sort more than 100,000
words. So I thought I'd do it in batches. Have a batch
in alphabetical order, then sort in another batch, etc,
etc. But not being able to do < and >, I cannot sort
in the new batch into the existing one. So I am kind of
stuck.

Nov 16 '05 #9
If you want to sort your strings you should put them in an array. Then it's
easy to sort them:

string[] arr = {"asd","wer", "bddfb", "yuioty", "ksadfa"};
Array.Sort(arr);
foreach(string s in arr)
{
//write to console, or do whatever:
Console.WriteLine(s);
}

this gives the following output:
asd
bddfb
ksadfa
wer
yuioty

I'm not sure if this way of doing it will give performance problems on
100.000 records... try it.

"Adrian" <aa@aa.aa> wrote in message
news:6e**************************@freeler.nl...
"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
You can't use "<" and ">" on string, but you asked if you could use "!="; that is possible:

Apologies for the messy question.
Working until late last night.

My problem is that I need to sort more than 100,000
words. So I thought I'd do it in batches. Have a batch
in alphabetical order, then sort in another batch, etc,
etc. But not being able to do < and >, I cannot sort
in the new batch into the existing one. So I am kind of
stuck.

Nov 16 '05 #10
Hi,

It's a different thing < than !=

If you want to compare 2 strings you can use String.Compare or
String.CompareTo

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Adrian" <no@spam.pls> wrote in message
news:52************************@freeler.nl...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

It does work of course,

Post an example with your problem and with the EXACT contents of the
strings


private void Form1_Load(object sender, System.EventArgs e)

{

if("monkey" < "donkey")

panel1.Text = "Monkey is smaller than donkey";

else

panel1.Text = "Monkey is not smaller than donkey";

}


Nov 16 '05 #11
"David Anton" <da**@tangiblesoftwaresolutions-dot-com.no-spam.invalid> wrote
in message news:41********@Usenet.com...
<snipped>

Thank you all for the responses. I will know what to do in future.
In the mean time I had to get on with the job and quickly wrote
a small BASIC program that did the job.
Nov 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: alexk | last post by:
I've a simple question. Why the following: words = "123#@$#$@^% wordB#@$".split('~`!@#$%^&*()_+-={},./') doesn't work? The length of the result vector is 1. I'm using ActivePython 2.4 Alex
11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
2
by: almurph | last post by:
Hi everyone, Hope that you can help me please? I have a string of the form: wordA wordB wordC wordD etc etc I want to de-duplicate it- that is, I want to remeove any repeated term...
2
by: almurph | last post by:
Intern Strings - am I usingthem right. I have heard a lot about intern string - so I wanted to use them to increas e speed of processing. I have a hastable that I am using to parse a string...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.