473,569 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lower

Hello,

I am comparing two strings in a LINQ query as follows:

where t.Name.StartsWi th(q)

I want to select the record even if t.Name is "New York" and q is
"new" ... I don't want case to affect it.

I changed it to:

where t.Name.StartsWi th(q.ToLower)

But I don't know how to do this to t.Name ...

Thank You,
Miguel
Jul 13 '08 #1
6 1523
shapper wrote:
I am comparing two strings in a LINQ query as follows:

where t.Name.StartsWi th(q)

I want to select the record even if t.Name is "New York" and q is
"new" ... I don't want case to affect it.

I changed it to:

where t.Name.StartsWi th(q.ToLower)

But I don't know how to do this to t.Name ...
If t.Name is a String I would assume you could use
ToLower there as well.

Arne
Jul 13 '08 #2
On Jul 13, 5:49*pm, shapper <mdmo...@gmail. comwrote:
Hello,

I am comparing two strings in a LINQ query as follows:

where t.Name.StartsWi th(q)

I want to select the record even if t.Name is "New York" and q is
"new" ... I don't want case to affect it.

I changed it to:

where t.Name.StartsWi th(q.ToLower)

But I don't know how to do this to t.Name ...
Never, ever, use ToLower/ToUpper for case-insensitive comparison. It
just doesn't work for some languages. Instead, use the appropriate
overload:

t.Name.StartsWi th(q, StringCompariso n.CurrentCultur eIgnoreCase)

Note the "CurrentCulture IgnoreCase" bit - this is the same behavior as
StartsWith with only 1 argument, but also ignores case. If you do
_not_ want to use culture-based comparison (e.g. if you're comparing
identifiers rather than user-produced text), you might want to
consider InvariantCultur eIgnoreCase, or even OrdinalIgnoreCa se.
Jul 13 '08 #3
On Jul 13, 8:16*pm, Pavel Minaev <int...@gmail.c omwrote:
On Jul 13, 5:49*pm, shapper <mdmo...@gmail. comwrote:
Hello,
I am comparing two strings in a LINQ query as follows:
where t.Name.StartsWi th(q)
I want to select the record even if t.Name is "New York" and q is
"new" ... I don't want case to affect it.
I changed it to:
where t.Name.StartsWi th(q.ToLower)
But I don't know how to do this to t.Name ...

Never, ever, use ToLower/ToUpper for case-insensitive comparison. It
just doesn't work for some languages. Instead, use the appropriate
overload:

t.Name.StartsWi th(q, StringCompariso n.CurrentCultur eIgnoreCase)

Note the "CurrentCulture IgnoreCase" bit - this is the same behavior as
StartsWith with only 1 argument, but also ignores case. If you do
_not_ want to use culture-based comparison (e.g. if you're comparing
identifiers rather than user-produced text), you might want to
consider InvariantCultur eIgnoreCase, or even OrdinalIgnoreCa se.
Hi,

I am just a little bit confused between:
InvariantCultur eIgnoreCase and CurrentCultureI gnoreCase

In this case I am using this in an AutoComplete.
So when a user writes "Ne", which is the value of q, then my Linq will
look for all records where Name starts with "Ne", "ne", "nE", ...

Which one should I use in this case? InvariantCultur eIgnoreCase or
CurrentCultureI gnoreCase?

Thanks,
Miguel
Jul 13 '08 #4
On Jul 14, 12:55*am, shapper <mdmo...@gmail. comwrote:
I am just a little bit confused between:
InvariantCultur eIgnoreCase and CurrentCultureI gnoreCase

In this case I am using this in an AutoComplete.
So when a user writes "Ne", which is the value of q, then my Linq will
look for all records where Name starts with "Ne", "ne", "nE", ...

Which one should I use in this case? InvariantCultur eIgnoreCase or
CurrentCultureI gnoreCase?
For people's names, CurrentCulture is definitely the best, since it's
comparison of strings in natural language, and it is directly visible
to the end user.
Jul 14 '08 #5
Hey there, the comments about using a
StringCompariso n.CurrentCultur eIgnoreCase are all correct. But if you
actually are going to to user ToLower on 2 strings to compare them, I
remember thinking that it is better in .NET to compare two uppercase strings.
Apparently there is some optimization of the framework for that. I think its
mentioned in "CLR via C#" (which is the second version of "Applied .NET
Framework Programming".
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"shapper" wrote:
Hello,

I am comparing two strings in a LINQ query as follows:

where t.Name.StartsWi th(q)

I want to select the record even if t.Name is "New York" and q is
"new" ... I don't want case to affect it.

I changed it to:

where t.Name.StartsWi th(q.ToLower)

But I don't know how to do this to t.Name ...

Thank You,
Miguel
Jul 14 '08 #6
On Jul 13, 11:16*pm, Pavel Minaev <int...@gmail.c omwrote:
Never, ever, use ToLower/ToUpper for case-insensitive comparison. It
just doesn't work for some languages. Instead, use the appropriate
overload:
I thought this was a strong enough statement that it warrants some
clarification, so here are the references:

http://blogs.msdn.com/michkap/archiv...15/551773.aspx
http://blogs.msdn.com/michkap/archiv...11/511557.aspx

And in general, I'd heartily recommend reading a couple of posts
Michael's blog to anyone who deals with Unicode (which is pretty much
every programmer out there, these days) to better understand the
issues involved.
Jul 15 '08 #7

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

Similar topics

2
3197
by: gf gf | last post by:
I read that lower() is deprecated. Unfortunately, I can't find the preferred way of lowercasing a string. What is it? Thanks PS Please cc me on all responses.
1
5960
by: tony wong | last post by:
the page has upper frame (submit record) and lower frame (show records). i wish to refresh lower frame once submit record at upper frame. i try this, it works to refresh the lower frame function ABC() { window.parent.mainFrame.location.reload();} <input type="button" value="refresh" onclick="return ABC()"></TD>
6
1580
by: Martin Hampl | last post by:
Hi, I am using PostgreSQL 7.4, but I did have the same problem with the last version. I indexed the column word (defined as varchar(64)) using lower(word). If I use the following query, everything is fine, the index is used and the query is executed very quickly: select * from token where lower(word) = 'saxophone';
17
11209
by: Janice | last post by:
char* line = "abcd"; How to convert the line to upper case and print? Any option for printf to do this? Thanx
4
2020
by: jimdscudder | last post by:
I am using a file watcher to watch for files changing. My problem is: the string file info returned is all LOWER CASE. Below is the important part of the code? Any suggestions? using System;
4
2248
by: Mark Gibson | last post by:
Hi, I've been playing about with array's, and found the concat operator '||' quite useful, apart from the fact that prepending an element places it in a lower subscript. Is there a way of either: a) prepending an element, but shifting existing elements up a subscript, so that the lower bound remains the same? eg: 1 ||> ARRAY -- new...
19
26430
by: Eric Lindsay | last post by:
Should HTML 4.01 Strict markup be done in upper case or in lower case? I understand that HTML allows either upper or lower case. I also notice that XHTML apparently requires lower case. However I saw some mention that the HTML DOM uses upper case for markup elements. So, should I worry about what this means? I am inclined to go with...
1
1363
by: lordhunter9r9za | last post by:
No One runs the world. ... Are you on track yet? About me: Warm, skilled, caring, friend of wild life . Charming... Yeah, and the hotest hotties think I'm sexy, sweet, and warm. magizian@magizians.zzn.com Television Could use alot of improvement. http://www.myspace.com/magizian 69.1331.g.zi.9R9.8.s
4
7837
by: Alexey Moskvin | last post by:
Hi! I have a set of strings (all letters are capitalized) at utf-8, russian language. I need to lower it, but my_string.lower(). Doesn't work. See sample script: # -*- coding: utf-8 -*- s1 = self.title s2 = self.title.lower() print s1 == s2
2
2872
Thekid
by: Thekid | last post by:
I had made a post about making a loop using letters instead of numbers and dshimer gave me this solution: for i in range(65,70): for j in range(65,70): for k in range(65,70): print chr(i),chr(j),chr(k) which used an example I had posted using numbers. That code works (thanks dshimer) but after toying with it I see...
0
7710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7935
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8144
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7692
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7992
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3677
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3666
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1235
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.