"Case of" for strings?

Hello

Surprisingly, Google didn't return threads in the defunct
borland.public.delphi.language.delphi.general newsgroup with "case of
string".

What is the recommended way to use the "Case Of" structure when
checking strings?

I found the following samples but would like to know if there's a
better way:

www.delphi3000.com/articles/article_2810.asp?SK=
http://delphi.about.com/cs/adptips2002/a/bltip0202_5.htm
http://delphishack.blogspot.com/2008/03/case-statement-using-string.html

Thank you.
0
Gilles
10/4/2008 11:26:25 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

24 Replies
3392 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

"Gilles Ganault" <nospam@nospam.com> wrote in message 
news:25343@forums.codegear.com...
>
> What is the recommended way to use the "Case Of" structure when
> checking strings?
>
> I found the following samples but would like to know if there's a
> better way:
>
> www.delphi3000.com/articles/article_2810.asp?SK=
> http://delphi.about.com/cs/adptips2002/a/bltip0202_5.htm
> http://delphishack.blogspot.com/2008/03/case-statement-using-string.html


One way is to have a parallel ordinal or enumerated value to test in the 
case. E.g. using a deck of cards as a trivial example, instead of this:

  if suit = 'Clubs' then ...
  else if suit = 'Hearts' ...

Do this:

type
  TSuit = (Hearts, Spades, Diamonds, Clubs);
const
  TSuitNames = array [TSuit] of string = ('Hearts', 'Spades', 'Diamonds', 
'Clubs');

....

{ passing param suit: TSuit }
begin
    case suit of
        Hearts: ...
        Spades: ...
        Diamonds: ...
        Clubs: ...
    end;

If this is no good for some reason then another way is to use a stringlist 
to add the strings to and then use the lookup index in the case:

    SuitList.CommaText := 'Hearts, Spades, Diamonds, Clubs';
....

    case SuitList.IndexOf(suit) of
        0: ... // hearts
        1: ... // spades
        2: ... // diamonds
        3: ... // clubs
    end;

-- 
Wayne Niddery - TeamB (www.teamb.com)
Tips to Get Published: http://dn.codegear.com/article/38467
Winwright, Inc. (www.winwright.ca)
0
Wayne
10/4/2008 12:20:58 PM
Gilles Ganault wrote:
> Hello
>
> Surprisingly, Google didn't return threads in the defunct
> borland.public.delphi.language.delphi.general newsgroup with "case of
> string".
>
> What is the recommended way to use the "Case Of" structure when
> checking strings?
>
> I found the following samples but would like to know if there's a
> better way:
>
> www.delphi3000.com/articles/article_2810.asp?SK=
> http://delphi.about.com/cs/adptips2002/a/bltip0202_5.htm
> http://delphishack.blogspot.com/2008/03/case-statement-using-string.html
>
> Thank you.
>   
Don't even dream of using Strings in Case of. Delphi Pascal does not 
support Strings in Case of.

I have discussed this in the past and the conclusion is to not use it at 
all! Unless you want to work more than necessary of course.
0
Yogi
10/4/2008 1:22:17 PM
Gilles Ganault wrote:

> What is the recommended way to use the "Case Of" structure when
> checking strings?

Use IndexText (or IndexStr if you need case sensitivity).

case IndexText(myStr,['Str0','Str1','Str2','Str3']) of
   0: // myStr = 'Str0';
   1:
   2:
   3:
else
   // no match
end;


-- 
Kent Briggs, kbriggs@spamcop.net
Briggs Softworks, http://www.briggsoft.com
0
Kent
10/4/2008 3:11:19 PM
Yogi Yang wrote:

> Don't even dream of using Strings in Case of. Delphi Pascal does not 
> support Strings in Case of.

I'm pretty sure he realizes that and is looking for a way to simulate it.


-- 
Kent Briggs, kbriggs@spamcop.net
Briggs Softworks, http://www.briggsoft.com
0
Kent
10/4/2008 3:12:50 PM
Kent Briggs wrote:
> Gilles Ganault wrote:
> 
>> What is the recommended way to use the "Case Of" structure when
>> checking strings?
> 
> Use IndexText (or IndexStr if you need case sensitivity).

Hm.  Must be more recent than D2006 - Help doesn't find it.  It would be 
a very handy function!

John
0
John
10/4/2008 5:16:57 PM
John Treder wrote:
> Kent Briggs wrote:
>> Gilles Ganault wrote:
>>> What is the recommended way to use the "Case Of" structure when
>>> checking strings?
>>
>> Use IndexText (or IndexStr if you need case sensitivity).
> 
> Hm.  Must be more recent than D2006 - Help doesn't find it.  It would be 
> a very handy function!

Just because it's not in the help doesn't mean it isn't there. Surely 
you've figured that out by now.

You have the source code. Text-searching tools are your friends.

cd source\Win32
grep -r IndexText *

And even if you didn't have it in your version of Delphi, it would be 
very simple to write. Take a string and an array. Loop through the array 
until you find the string, and return the array index. Return -1 if you 
don't find it.

-- 
Rob
0
Rob
10/4/2008 6:06:05 PM
John Treder wrote:

> Hm.  Must be more recent than D2006 - Help doesn't find it.  It would be 
> a very handy function!

It's in the StrUtils unit. It doesn't show up in the D2005 help either 
but it works there after you add that to your uses clause.

-- 
Kent Briggs, kbriggs@spamcop.net
Briggs Softworks, http://www.briggsoft.com
0
Kent
10/4/2008 7:14:45 PM
"Wayne Niddery" <wniddery@chaffaci.on.ca> wrote in message 
news:25349@forums.codegear.com...
> "Gilles Ganault" <nospam@nospam.com> wrote in message
> news:25343@forums.codegear.com...
>>
>> What is the recommended way to use the "Case Of" structure when
>> checking strings?
>>
>> I found the following samples but would like to know if there's a
>> better way:
>>
>> www.delphi3000.com/articles/article_2810.asp?SK=
>> http://delphi.about.com/cs/adptips2002/a/bltip0202_5.htm
>> http://delphishack.blogspot.com/2008/03/case-statement-using-string.html
>
>
> One way is to have a parallel ordinal or enumerated value to test in the
> case. E.g. using a deck of cards as a trivial example, instead of this:
>
>  if suit = 'Clubs' then ...
>  else if suit = 'Hearts' ...
>
> Do this:
>
> type
>  TSuit = (Hearts, Spades, Diamonds, Clubs);
> const
>  TSuitNames = array [TSuit] of string = ('Hearts', 'Spades', 'Diamonds',
> 'Clubs');
>

  Anything wrong with casting the first character of a string literal to a char 
and using that (assuming the passed strings will have unique first characters)?

>
> { passing param suit: TSuit }
> begin
>    case suit of
>        Hearts: ...
>        Spades: ...
>        Diamonds: ...
>        Clubs: ...
>    end;
>
> If this is no good for some reason then another way is to use a stringlist
> to add the strings to and then use the lookup index in the case:
>
>    SuitList.CommaText := 'Hearts, Spades, Diamonds, Clubs';
> ...
>
>    case SuitList.IndexOf(suit) of
>        0: ... // hearts
>        1: ... // spades
>        2: ... // diamonds
>        3: ... // clubs
>    end;
>
> -- 
> Wayne Niddery - TeamB (www.teamb.com)
> Tips to Get Published: http://dn.codegear.com/article/38467
> Winwright, Inc. (www.winwright.ca)
0
Michael
10/5/2008 12:07:17 AM
Rob Kennedy wrote:
> John Treder wrote:
>> Kent Briggs wrote:
>>> Gilles Ganault wrote:
>>>> What is the recommended way to use the "Case Of" structure when
>>>> checking strings?
>>> Use IndexText (or IndexStr if you need case sensitivity).
>> Hm.  Must be more recent than D2006 - Help doesn't find it.  It would be 
>> a very handy function!
> 
> Just because it's not in the help doesn't mean it isn't there. Surely 
> you've figured that out by now.
Yep.  And in StrUtils, one of the worst-documented parts of the whole 
shebang.

Kim Kokkonen, where are you?

> And even if you didn't have it in your version of Delphi, it would be 
> very simple to write. Take a string and an array. Loop through the array 
> until you find the string, and return the array index. Return -1 if you 
> don't find it.
> 
It was clearly easy to write.  But it's even easier to use something 
that's just sitting there drinking coffee.

John
0
John
10/5/2008 2:50:35 AM
The best way if to use
If ... then ...
else if ... then ...
else if ... then ...


i try one day a program with 32000 lines of

If ... then ...
else if ... then ...
else if ... then ...
....
else ..

and it's was very very fast (i was even a little surprised) !

stephane

Http://www.arkadia.com/fra/
Http://www.arkadia.com/usa/
Http://www.arkadia.com/rus/


"Gilles Ganault" <nospam@nospam.com> wrote in message 
news:25343@forums.codegear.com...
> Hello
>
> Surprisingly, Google didn't return threads in the defunct
> borland.public.delphi.language.delphi.general newsgroup with "case of
> string".
>
> What is the recommended way to use the "Case Of" structure when
> checking strings?
>
> I found the following samples but would like to know if there's a
> better way:
>
> www.delphi3000.com/articles/article_2810.asp?SK=
> http://delphi.about.com/cs/adptips2002/a/bltip0202_5.htm
> http://delphishack.blogspot.com/2008/03/case-statement-using-string.html
>
> Thank you.
0
loki
10/5/2008 10:16:29 AM
Hello Kent,

> Use IndexText (or IndexStr if you need case sensitivity).
> 
> case IndexText(myStr,['Str0','Str1','Str2','Str3']) of
>    0: // myStr = 'Str0';
>    1:
>    2:
>    3:
> else
>    // no match
> end;

It this faster than comparing string with "IF" ?

Thank you
-- 
Charalabos Michael - [Creation Power] - http://www.creationpower.gr
0
Charalampos
10/6/2008 12:03:03 AM
Charalabos Michael wrote:
> Hello Kent,
> 
>> Use IndexText (or IndexStr if you need case sensitivity).

> It this faster than comparing string with "IF" ?

Probably not but it's prettier. For a long list you could also use a 
sorted TStringList where the Find command (and possibly IndexOf ?) uses 
a binary search algorithm, as I recall.


-- 
Kent Briggs, kbriggs@spamcop.net
Briggs Softworks, http://www.briggsoft.com
0
Kent
10/6/2008 6:09:52 AM
Wayne Niddery wrote:

> One way is to have a parallel ordinal or enumerated value to test in the 
> case. E.g. using a deck of cards as a trivial example, instead of this:
> [...]
> If this is no good for some reason then another way is to use a stringlist 
> to add the strings to and then use the lookup index in the case:
> 
>     SuitList.CommaText := 'Hearts, Spades, Diamonds, Clubs';
> ...
> 
>     case SuitList.IndexOf(suit) of
>         0: ... // hearts
>         1: ... // spades
>         2: ... // diamonds
>         3: ... // clubs
>     end;

First of all, you should probably *not* test hard-coded strings in your code
if you ever want to translate your program to a different (user) language.

That aside, you could use a combination of both methods, with a little more
cost for setting up:

SuitList.AddObject('Hearts', TObject(Hearts));
SuitList.AddObject('Spades', TObject(Spades));
....

    case TSuit(SuitList.Objects[SuitList.IndexOf(suit)]) of
        Hearts: ...
        Spades: ...
        Diamonds: ...
        Clubs: ...
    end;

Pro: This method is 'sort and insertion-safe', i.e. the case labels will not
change just because you sort the list, or add a string in the middle of the
list. It is also 'translation-safe', something all other suggestions have
forgotten.

Con: The line "case TSuit(SuitList.Objects[SuitList.IndexOf(suit)]) of"
assumes you get a hit on IndexOf, there can be no 'default' case. This is
easy to fix with an extra function call, but you have to remember to do it.

Both of those methods have the disadvantage that they move the actual strings
away from the case statement (If you see this as a disadvantage).

Speed-wise, on a small list, the "if-then-else-if..." ladder will definitely
be much faster, on a list 'large enough' the binary search performed by
IndexOf on a sorted list will make this method faster, but I have no idea
where the crossing point will be...

Did I say that this way is 'translation-safe'?
:-)

-- 
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm  
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
0
Anders
10/6/2008 7:15:23 AM
> {quote:title=Gilles Ganault wrote:}{quote}
> Hello
> 
> Surprisingly, Google didn't return threads in the defunct
> borland.public.delphi.language.delphi.general newsgroup with "case of
> string".
> 
> What is the recommended way to use the "Case Of" structure when
> checking strings?

Here is a method theme I've used a number of variations on ...
{code}
const
// Wrap the strings between delimiters and pad them to the same length 
  OptionCount = 4;  // This must match the number of strings
  OptionStrings =    // Did I mention that all strings must be of same length - and lowercase?
    '|one     ' +
    '|second  ' +
    '|3       ' +
    '|quattro ';

function StrIndex(str:String; Options:String):Integer;
begin
  // trim input whitespace, convert to lowercase, and add padding
  Result := Pos('|'+lowercase(trim(str))+' ', Options);
  if Result > 0 // we found the string, so let's calculate the option "index"
   then Result := (Result  div (Length(Options) div OptionCount)) + 1;
end;

begin
  case StrIndex(ParamStr(1), OptionStrings) of
    0 : Writeln('No params');
    1 : NumeroUno;
    2 : // you get the idea ...
{code}
If you remove the right side padding from the lookup string, you can do partial string matching - although you cannot guarantee no duplicate partial matches without adding more code.  
There is one drawback to this method - it is order sensitive - Add an option in the middle of the list or move an option in the list - and you move the index.  As long as you add more strings at the end - you are ok.

A better alternative is to build a lookup table and associate a known constant with each string. This can be done in the initialization section of the unit, so that you don't have to rebuild the table every time you need it.

--
http://Lars.Fosdal.com - There are no stupid questions
0
Lars
10/6/2008 7:23:01 AM
Anders Isaksson wrote:
> Wayne Niddery wrote:
>> One way is to have a parallel ordinal or enumerated value to test in the 
>> case. E.g. using a deck of cards as a trivial example, instead of this:
>> [...]
>> If this is no good for some reason then another way is to use a stringlist 
>> to add the strings to and then use the lookup index in the case:
>>
>>     SuitList.CommaText := 'Hearts, Spades, Diamonds, Clubs';
>> ...
>>
>>     case SuitList.IndexOf(suit) of
>>         0: ... // hearts
>>         1: ... // spades
>>         2: ... // diamonds
>>         3: ... // clubs
>>     end;
> 
> First of all, you should probably *not* test hard-coded strings in your code
> if you ever want to translate your program to a different (user) language.
> 
> That aside, you could use a combination of both methods, with a little more
> cost for setting up:
> 
> SuitList.AddObject('Hearts', TObject(Hearts));
> SuitList.AddObject('Spades', TObject(Spades));
> ...
> 
>     case TSuit(SuitList.Objects[SuitList.IndexOf(suit)]) of
>         Hearts: ...
>         Spades: ...
>         Diamonds: ...
>         Clubs: ...
>     end;
> 
> Pro: This method is 'sort and insertion-safe', i.e. the case labels will not
> change just because you sort the list, or add a string in the middle of the
> list. It is also 'translation-safe', something all other suggestions have
> forgotten.

Yours isn't any more translation-safe than the others. You're still 
adding hard-coded strings to your list. Whatever translation efforts you 
do on your string literals could just as easily be applied to the 
literals in any of the other suggestions.

Aside from the point that the order of the list doesn't matter, I think 
the next advantage of your suggestion is that the case labels have names 
from an enum, and the declaration order of the enum values is also 
irrelevant.

-- 
Rob
0
Rob
10/6/2008 7:36:13 AM
Rob Kennedy wrote:

> Yours isn't any more translation-safe than the others. You're still 
> adding hard-coded strings to your list.

But whatever foreign word you translate the strings to, with my method the
case labels have no dependency on a CRC (which will change) sort order (which
will change), hash value (which will change) or actual content (which will
change).

Granted, it's the same for "the if-then-else..." ladder. But the whole
exercise was to find an alternative to that, wasn't it?

-- 
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm  
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
0
Anders
10/6/2008 7:51:29 AM
Lars Fosdal wrote:

> A better alternative is to build a lookup table and associate a known
> constant with each string. This can be done in the initialization section
> of the unit, so that you don't have to rebuild the table every time you
> need it.

That was my suggestion (a number of posts up/down depending on your reading
preferences).

-- 
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm  
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
0
Anders
10/6/2008 7:52:46 AM
> {quote:title=Anders Isaksson wrote:}{quote}
> Lars Fosdal wrote:
> 
> > A better alternative is to build a lookup table and associate a known
> > constant with each string. This can be done in the initialization section
> > of the unit, so that you don't have to rebuild the table every time you
> > need it.
> 
> That was my suggestion (a number of posts up/down depending on your reading
> preferences).

Yes, that will work if you add an exception handler to catch mismatches.

--
http://Lars.Fosdal.com - There are no stupid questions
0
Lars
10/6/2008 8:05:17 AM
Lars Fosdal wrote:

> Yes, that will work if you add an exception handler to catch mismatches.

No need for exceptions:

  t := SuitList.IndexOf(suit);
  if t >= 0 then 
    case TSuit(SuitList.Objects[t]) of
      Hearts: ...
      ...
      else 
        ;// data error, suit in list, but case value not in case
    end
  else
   ;// actual default case, suit not in list

Actually I recommended creating a small function, so you could have just a
single a default case (no match) as usual:

  case TSuit(MatchString(suit, SuitList)) of
    Hearts: ...
    ...
    else  ;// default case
  end;

-- 
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm  
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
0
Anders
10/6/2008 9:14:06 AM
> {quote:title=Anders Isaksson wrote:}{quote}
> Lars Fosdal wrote:
> 
> > Yes, that will work if you add an exception handler to catch mismatches.
> 
> No need for exceptions:
> 
>   t := SuitList.IndexOf(suit);
>   if t >= 0 then 
>     case TSuit(SuitList.Objects[t]) of
>       Hearts: ...
>       ...
>       else 
>         ;// data error, suit in list, but case value not in case
>     end
>   else
>    ;// actual default case, suit not in list
> 
> Actually I recommended creating a small function, so you could have just a
> single a default case (no match) as usual:
> 
>   case TSuit(MatchString(suit, SuitList)) of
>     Hearts: ...
>     ...
>     else  ;// default case
>   end;

There might be an argument for using numeric constants instead of enums.  You could drop the typecasts and you would not need a "not defined" enum value for each type.

--
http://Lars.Fosdal.com - There are no stupid questions
0
Lars
10/6/2008 10:39:50 AM
Lars Fosdal wrote:

> There might be an argument for using numeric constants instead of enums.
> You could drop the typecasts and you would not need a "not defined" enum
> value for each type.

At least in D5, it seems range check does not stop the following code from
working:

  Suit := TSuit(-1);
  case Suit of
   Hearts: ...
   ...
   else // execution goes here
  end;

-- 
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm  
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
0
Anders
10/6/2008 11:02:37 AM
> {quote:title=Anders Isaksson wrote:}{quote}
> Lars Fosdal wrote:
> 
> > There might be an argument for using numeric constants instead of enums.
> > You could drop the typecasts and you would not need a "not defined" enum
> > value for each type.
> 
> At least in D5, it seems range check does not stop the following code from
> working:
> 
>   Suit := TSuit(-1);
>   case Suit of
>    Hearts: ...
>    ...
>    else // execution goes here
>   end;

Works in D2007 as well.  No hints, warnings or runtime issues.
Almost scary :)

btw - if you put code markers around your example code, it looks a lot better in the web forum.

\{code}
 // delphi code here
\{code}

https://forums.codegear.com/message.jspa?messageID=25754#25754

--
http://Lars.Fosdal.com - There are no stupid questions
0
Lars
10/6/2008 11:39:47 AM
Anders Isaksson wrote:
> Rob Kennedy wrote:
>> Yours isn't any more translation-safe than the others. You're still 
>> adding hard-coded strings to your list.
> 
> But whatever foreign word you translate the strings to, with my method the
> case labels have no dependency on a CRC (which will change) sort order (which
> will change), hash value (which will change) or actual content (which will
> change).

Nobody else's suggestions relied on any of those things, either. They've 
relied on order, but not sort order.

-- 
Rob
0
Rob
10/6/2008 1:19:34 PM
Rob Kennedy wrote:

> Nobody else's suggestions relied on any of those things, either. They've 
> relied on order, but not sort order.

I'm sorry, I followed my own idea of using a *sorted* stringlist, to benefit
from the binary search, something which is *very* hard to implement
translatable with the other methods.

Satisfied now?

-- 
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm  
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
0
Anders
10/6/2008 2:30:26 PM
Reply:

Similar Artilces:

pulling out "a","an", "the" from beginning of strings
I need to pull out articles "a", "an", and "the" from the beginning of title strings so that they sort properly in MySQL. What is the best way to accomplish that if I have a single $scalar with the whole title in it? Thanks, Tim -- Tim McGeary tim.mcgeary@lehigh.edu --=-weUphL4mkB1WR5g+DMDc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, 2004-08-24 at 15:04, Tim McGeary wrote: > I need to pull out articles "a", "an", and "the" from the beginning of=20 >...

Session in this format["string"]["string"]
Is that possible to have session variable in 2 dimensional array like when we are using Cookie? If so, can you give the syntax in C# please? Thanks.....Best regards,Ron. You can save a 2 dimendional array to a session, however session's are not 2 dimentional. You can: Session.Add("WhatAreNinjas", "Ninjas Are Cool"); and: string[,] astrNinja = new string[2, 2];astrNinja[0, 0] = "doood";astrNinja[0, 1] = "Hurry up and release Team Foundation Server";astrNinja[1, 0] = "ok ok, i know you have to code it, and test it, and all that jazz... but... come on... release it... release iT NOW!";a...

Macro to switch between L"" and "" in case of a hardcoded string
Hi, In order to keep my code compilable (or to a certain extent at least (certain classes)) between BCB5 and CB2009 I want to change string operations, e.g. String x = "input" (BCB5) to String x = L"input" (CB2009) I realise that the MBCS variant builds just as nicely as the unicode variant in CB2009 but then a conversion is done, so I think it's better, to use the second line variant. To not have to constantly do: #ifdef _DELPHI_STRING_UNICODE String x = L"input" ; #else String x = "input" #endif I was wondering what...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

How to Convert "string" to "DateTime"
hi , i have a problem i have an textarea that i want to convert to DateTime format (dd/MM/yyyy) . the data in the textarea is (dd/MM/yyyy for example 21/12/2005). i need it to add this data in sql server , in smalldatetime formation colum . plz help.     Wouldn't you just use: DateTime dt1 = DateTime.Parse( stringToParse, formatProvider, styles) This doesn't quite seem like a SQL Server question ... but in ASP.NET you can convert a string to a date using the DateTime.Parse(string) method. Then you could use this as the value of a parameter to a stored procedure with t...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

"Me" is better than "You"
Yes I know, strings are frozen. But let me talk about it, I really can't get through the idea of a PC talkin to me. I consider my PC as an extension of myself, not a dumb companion who addresses Me as You. Yes there are times when I get angry with Him while I work and get wrong calculations etc.., but it really is my fault, Me using wrong istructions and eventually wanting to find someone else to blame, but it's Me. And yes, I consider Thunderbird my mail program, reading my mail on my PC as Me. So I personally like to have Me in the header bar as a compact address ...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

"-" not "_"
I wrote a SQL statement in the data tab. I wrote a bunch of alaises as example ' word-type ' but when I hit the layout tab it converts the "-" to "_". So now my field name is ' word_type '. Is there any way to prevent this? CardGunner Don' use a hypen ( - ).  It isn't a valid character for column names.   See http://searchsqlserver.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid87_gci1188931,00.html   Here's an excerpt about column names: Letters as defined in the Unicode Standard 2.0 Decimal numbers from either B...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

Web resources about - "Case of" for strings? - embarcadero.delphi.general

Resources last updated: 1/22/2016 12:32:48 PM