f



String or string

I am doing something where I do=20
If "force" || "spells"
Puts "blah"



When I use it it gives a warning about comparing strings, what's happening a=
nd how do I fix it?

Scratch.mit.edu. Go there!

-gbear605=

0
Garrison
12/13/2010 10:53:55 PM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

7 Replies
1531 Views

Similar Articles

[PageSpeed] 46

It doesn't seem to mind if those are pre-assigned ...

ruby-1.9.2-p0 > if "force" || "spells"
ruby-1.9.2-p0 ?>  puts "blah"
ruby-1.9.2-p0 ?>  end
(irb):3: warning: string literal in condition
(irb):3: warning: string literal in condition
blah
  => nil
ruby-1.9.2-p0 > f = "force"
  => "force"
ruby-1.9.2-p0 > s = "spells"
  => "spells"
ruby-1.9.2-p0 > if f || s
ruby-1.9.2-p0 ?>  puts "blah"
ruby-1.9.2-p0 ?>  end
blah
  => nil

On 14/12/10 11:53, Garrison Taylor wrote:
> "force" || "spells"
>    

0
Sam
12/13/2010 11:08:51 PM
[Note:  parts of this message were removed to make it a legal post.]

On Mon, Dec 13, 2010 at 4:53 PM, Garrison Taylor
<garrisontaylor@gmail.com>wrote:

> I am doing something where I do
> If "force" || "spells"
> Puts "blah"
>
>
>
> When I use it it gives a warning about comparing strings, what's happening
> and how do I fix it?
>
> Scratch.mit.edu. Go there!
>
> -gbear605
>

|| is a boolean method meaning "or". It is concerned with the truthiness and
falsiness of its parameters. The set of falsy objects is { false , nil },
everything else is truthy. That means that strings are truthy, so when you
say "force" || "spells" it looks at "force", sees it isn't false and it
isn't nil, and so is considered true. Every time.

So "force" || "spells" will always return "force", a truthy value, to the if
statement. Thus the if statement will always execute.

if "force" || "spells"
  puts "blah"
end

is the same as

if "force"
  puts "blah"
end

is the same as

if true
  puts "blah"
end

is the same as

puts "blah"



That is probably not what you wanted, so it warns you of the issue.

0
Josh
12/13/2010 11:09:15 PM
When I typed it I wasn't looking at it, it was actually=20

u2 =3D gets.chomp
 If u2 !=3D "force" || "spells"
  Puts "blah"

Scratch.mit.edu. Go there!

-gbear605

On Dec 13, 2010, at 6:09 PM, Josh Cheek <josh.cheek@gmail.com> wrote:

> On Mon, Dec 13, 2010 at 4:53 PM, Garrison Taylor
> <garrisontaylor@gmail.com>wrote:
>=20
>> I am doing something where I do
>> If "force" || "spells"
>> Puts "blah"
>>=20
>>=20
>>=20
>> When I use it it gives a warning about comparing strings, what's happenin=
g
>> and how do I fix it?
>>=20
>> Scratch.mit.edu. Go there!
>>=20
>> -gbear605
>>=20
>=20
> || is a boolean method meaning "or". It is concerned with the truthiness a=
nd
> falsiness of its parameters. The set of falsy objects is { false , nil },
> everything else is truthy. That means that strings are truthy, so when you=

> say "force" || "spells" it looks at "force", sees it isn't false and it
> isn't nil, and so is considered true. Every time.
>=20
> So "force" || "spells" will always return "force", a truthy value, to the i=
f
> statement. Thus the if statement will always execute.
>=20
> if "force" || "spells"
>  puts "blah"
> end
>=20
> is the same as
>=20
> if "force"
>  puts "blah"
> end
>=20
> is the same as
>=20
> if true
>  puts "blah"
> end
>=20
> is the same as
>=20
> puts "blah"
>=20
>=20
>=20
> That is probably not what you wanted, so it warns you of the issue.

0
Garrison
12/13/2010 11:27:39 PM
Same problem, though. That's the same thing as

    if (u2 !=3D "...") || true

Which, of course, is the same thing as "if true".

Did you mean:

   if u2 !=3D "force" && u2 !=3D "spells"

...perhaps?

On Mon, Dec 13, 2010 at 3:27 PM, Garrison Taylor
<garrisontaylor@gmail.com> wrote:
> When I typed it I wasn't looking at it, it was actually
>
> u2 =3D gets.chomp
> =A0If u2 !=3D "force" || "spells"
> =A0Puts "blah"
>
> Scratch.mit.edu. Go there!
>
> -gbear605
>
> On Dec 13, 2010, at 6:09 PM, Josh Cheek <josh.cheek@gmail.com> wrote:
>
>> On Mon, Dec 13, 2010 at 4:53 PM, Garrison Taylor
>> <garrisontaylor@gmail.com>wrote:
>>
>>> I am doing something where I do
>>> If "force" || "spells"
>>> Puts "blah"
>>>
>>>
>>>
>>> When I use it it gives a warning about comparing strings, what's happen=
ing
>>> and how do I fix it?
>>>
>>> Scratch.mit.edu. Go there!
>>>
>>> -gbear605
>>>
>>
>> || is a boolean method meaning "or". It is concerned with the truthiness=
 and
>> falsiness of its parameters. The set of falsy objects is { false , nil }=
,
>> everything else is truthy. That means that strings are truthy, so when y=
ou
>> say "force" || "spells" it looks at "force", sees it isn't false and it
>> isn't nil, and so is considered true. Every time.
>>
>> So "force" || "spells" will always return "force", a truthy value, to th=
e if
>> statement. Thus the if statement will always execute.
>>
>> if "force" || "spells"
>> =A0puts "blah"
>> end
>>
>> is the same as
>>
>> if "force"
>> =A0puts "blah"
>> end
>>
>> is the same as
>>
>> if true
>> =A0puts "blah"
>> end
>>
>> is the same as
>>
>> puts "blah"
>>
>>
>>
>> That is probably not what you wanted, so it warns you of the issue.
>
>

0
Ross
12/14/2010 12:57:32 AM
I want it to puts blah if u2 isn't force or spells.

Scratch.mit.edu. Go there!

-gbear605

On Dec 13, 2010, at 7:57 PM, Ross Harvey <chaos@ross.aero> wrote:

> Same problem, though. That's the same thing as
>=20
>    if (u2 !=3D "...") || true
>=20
> Which, of course, is the same thing as "if true".
>=20
> Did you mean:
>=20
>   if u2 !=3D "force" && u2 !=3D "spells"
>=20
> ...perhaps?
>=20
> On Mon, Dec 13, 2010 at 3:27 PM, Garrison Taylor
> <garrisontaylor@gmail.com> wrote:
>> When I typed it I wasn't looking at it, it was actually
>>=20
>> u2 =3D gets.chomp
>>  If u2 !=3D "force" || "spells"
>>  Puts "blah"
>>=20
>> Scratch.mit.edu. Go there!
>>=20
>> -gbear605
>>=20
>> On Dec 13, 2010, at 6:09 PM, Josh Cheek <josh.cheek@gmail.com> wrote:
>>=20
>>> On Mon, Dec 13, 2010 at 4:53 PM, Garrison Taylor
>>> <garrisontaylor@gmail.com>wrote:
>>>=20
>>>> I am doing something where I do
>>>> If "force" || "spells"
>>>> Puts "blah"
>>>>=20
>>>>=20
>>>>=20
>>>> When I use it it gives a warning about comparing strings, what's happen=
ing
>>>> and how do I fix it?
>>>>=20
>>>> Scratch.mit.edu. Go there!
>>>>=20
>>>> -gbear605
>>>>=20
>>>=20
>>> || is a boolean method meaning "or". It is concerned with the truthiness=
 and
>>> falsiness of its parameters. The set of falsy objects is { false , nil }=
,
>>> everything else is truthy. That means that strings are truthy, so when y=
ou
>>> say "force" || "spells" it looks at "force", sees it isn't false and it
>>> isn't nil, and so is considered true. Every time.
>>>=20
>>> So "force" || "spells" will always return "force", a truthy value, to th=
e if
>>> statement. Thus the if statement will always execute.
>>>=20
>>> if "force" || "spells"
>>>  puts "blah"
>>> end
>>>=20
>>> is the same as
>>>=20
>>> if "force"
>>>  puts "blah"
>>> end
>>>=20
>>> is the same as
>>>=20
>>> if true
>>>  puts "blah"
>>> end
>>>=20
>>> is the same as
>>>=20
>>> puts "blah"
>>>=20
>>>=20
>>>=20
>>> That is probably not what you wanted, so it warns you of the issue.
>>=20
>>=20
>=20

0
Garrison
12/14/2010 1:58:18 AM
ruby-1.9.2-p0 > u2 = "foo"
  => "foo"
ruby-1.9.2-p0 > puts "blah" unless ["force", "spells"].include?(u2)
blah
  => nil
ruby-1.9.2-p0 > u2 = "force"
  => "force"
ruby-1.9.2-p0 > puts "blah" unless ["force", "spells"].include?(u2)
  => nil
ruby-1.9.2-p0 > u2 = "spells"
  => "spells"
ruby-1.9.2-p0 > puts "blah" unless ["force", "spells"].include?(u2)
  => nil


On 14/12/10 14:58, Garrison Taylor wrote:
> I want it to puts blah if u2 isn't force or spells.
>
> Scratch.mit.edu. Go there!
>
> -gbear605
>
> On Dec 13, 2010, at 7:57 PM, Ross Harvey<chaos@ross.aero>  wrote:
>
>    
>> Same problem, though. That's the same thing as
>>
>>     if (u2 != "...") || true
>>
>> Which, of course, is the same thing as "if true".
>>
>> Did you mean:
>>
>>    if u2 != "force"&&  u2 != "spells"
>>
>> ...perhaps?
>>
>> On Mon, Dec 13, 2010 at 3:27 PM, Garrison Taylor
>> <garrisontaylor@gmail.com>  wrote:
>>      
>>> When I typed it I wasn't looking at it, it was actually
>>>
>>> u2 = gets.chomp
>>>   If u2 != "force" || "spells"
>>>   Puts "blah"
>>>
>>> Scratch.mit.edu. Go there!
>>>
>>> -gbear605
>>>
>>> On Dec 13, 2010, at 6:09 PM, Josh Cheek<josh.cheek@gmail.com>  wrote:
>>>
>>>        
>>>> On Mon, Dec 13, 2010 at 4:53 PM, Garrison Taylor
>>>> <garrisontaylor@gmail.com>wrote:
>>>>
>>>>          
>>>>> I am doing something where I do
>>>>> If "force" || "spells"
>>>>> Puts "blah"
>>>>>
>>>>>
>>>>>
>>>>> When I use it it gives a warning about comparing strings, what's happening
>>>>> and how do I fix it?
>>>>>
>>>>> Scratch.mit.edu. Go there!
>>>>>
>>>>> -gbear605
>>>>>
>>>>>            
>>>> || is a boolean method meaning "or". It is concerned with the truthiness and
>>>> falsiness of its parameters. The set of falsy objects is { false , nil },
>>>> everything else is truthy. That means that strings are truthy, so when you
>>>> say "force" || "spells" it looks at "force", sees it isn't false and it
>>>> isn't nil, and so is considered true. Every time.
>>>>
>>>> So "force" || "spells" will always return "force", a truthy value, to the if
>>>> statement. Thus the if statement will always execute.
>>>>
>>>> if "force" || "spells"
>>>>   puts "blah"
>>>> end
>>>>
>>>> is the same as
>>>>
>>>> if "force"
>>>>   puts "blah"
>>>> end
>>>>
>>>> is the same as
>>>>
>>>> if true
>>>>   puts "blah"
>>>> end
>>>>
>>>> is the same as
>>>>
>>>> puts "blah"
>>>>
>>>>
>>>>
>>>> That is probably not what you wanted, so it warns you of the issue.
>>>>          
>>>
>>>        
>>      
>    

0
Sam
12/14/2010 2:03:58 AM
On Tue, Dec 14, 2010 at 3:03 AM, Sam Duncan <sduncan@wetafx.co.nz> wrote:
> ruby-1.9.2-p0 > u2 =3D "foo"
> =A0=3D> "foo"
> ruby-1.9.2-p0 > puts "blah" unless ["force", "spells"].include?(u2)
> blah
> =A0=3D> nil
> ruby-1.9.2-p0 > u2 =3D "force"
> =A0=3D> "force"
> ruby-1.9.2-p0 > puts "blah" unless ["force", "spells"].include?(u2)
> =A0=3D> nil
> ruby-1.9.2-p0 > u2 =3D "spells"
> =A0=3D> "spells"
> ruby-1.9.2-p0 > puts "blah" unless ["force", "spells"].include?(u2)
> =A0=3D> nil

%w can be nicely used here:

Ruby version 1.9.1
irb(main):001:0> %w{foo force spells}.each do |s|
irb(main):002:1* printf "Testing %p\n", s
irb(main):003:1> puts 'blah1' unless %w{force spells}.include? s
irb(main):004:1> puts 'blah2' unless s =3D=3D "force" || s =3D=3D "spells"
irb(main):005:1> puts 'blah3' unless /\A(?:force|spells)\z/ =3D~ s
irb(main):006:1> end
Testing "foo"
blah1
blah2
blah3
Testing "force"
Testing "spells"
=3D> ["foo", "force", "spells"]
irb(main):007:0>

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

0
Robert
12/14/2010 8:33:09 AM
Reply:

Similar Artilces:

String to htmlFriendly string
Hi!I was wondering if anyone knows if there is a simple way to make astring html friendly within the address bar?What I mean is that my servlet has a string with odd characters+,-,*,^,etc and I am concerned that attaching it to the url (as inwww.mydomain.com?uid=dude&pwd=dkdf8&%*#dfj) will cause the link tobreak.So I am trying to figure out how to most easily convert the "pwd"field to an url friendly string, and back again so that the next pagecould use it.Thanks!!! tiewknvc9 wrote:> Hi!> > I was wondering if anyone knows if there is a simple way to make a> string html friendly within the address bar?> > What I mean is that my servlet has a string with odd characters> +,-,*,^,etc and I am concerned that attaching it to the url (as in> www.mydomain.com?uid=dude&pwd=dkdf8&%*#dfj) will cause the link to> break.> > So I am trying to figure out how to most easily convert the "pwd"> field to an url friendly string, and back again so that the next page> could use it.> > Thanks!!!> http://java.sun.com/j2se/1.4.2/docs/api/java/net/URI.htmlI haven't checked this carefully but I believe that this will do what you want:URI uri = new URI( "insert crazy characters here" ); tiewknvc9 wrote:> Hi!> > I was wondering if anyone knows if there is a simple way to make a> string html friendly within the address bar?> > What I mean is that my servlet has a string with odd characters&g...

How compress a string into a compressed string?
Hi! I use VC++.NET 2003. I want to compress following text string. I store following text in std::string. std::string a="2B3A2BF0BCD8773D23BEE5550A56E86AF6CF64911214862625027CE7032451282E33F0BFB09D69091D39B1A1788E1A707E50A1948038500CF2044163F379912AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7AD8B59848C7670C94B29B54D2379E2E7A"; I need to compress above string before transfering it from my server application to client application. How do I compress above string into a compressed string (for example, std::string b;). Any help will be appreciated your string looks like a hexdump of 320 bytes, where the last 256 are repetitions of a 16-byte-sequence. you may just not transmit the repeated data after the first sequence. but possibly you want to compress varying bytes and transmit them as text? then better compress the bytes and later create an efficient text-representations out of the results. you may replace the hex-ascii-encoding with BASE64-encoding, to have shorter strings to transmit. for a .NET-compression-component, you have ...

selecting a string from a string array
Right now i have the user input&nbsp;the first&nbsp;char of a string they what to search for.&nbsp; Then it searches for any string that has that char in the first index place for example the 1D array is 111 222 333 122 344 112 and if the user inputs a 1 then the result is 111 122 112.&nbsp;I have that working what i need help is now i want to take that new 1D array and what ever the user selects then that string from the new&nbsp;1D array will be displayed.&nbsp; Like i said i can go as far as get the new 1d array of string but i need help with the selection of the string from the new array any help will be greatly appreciated &nbsp; &nbsp; &nbsp; Brandon search string.vi: http://forums.ni.com/attachments/ni/170/325973/1/search string.vi i am using 8.5 brandon20 wrote: I have that working what i need help is now i want to take that new 1D array and what ever the user selects then that string from the new&nbsp;1D array will be displayed.&nbsp; Like i said i can go as far as get the new 1d array of string but i need help with the selection of the string from the new array any help will be greatly appreciated Hi Brandon, which selected string do you mean? If the user can change the selection, i recommend to use an event structure. Mike what i meant by select the string is that the user can highlight one&nbsp;of the strings from the new array and which ever one is highlighted then that one is displayed.&nbsp; So as for t...

String and list of strings concatenation
A procedure with the following signature proc setMessage {msg args} should consider "msg" as a string and "args" as a list of strings with arbitrary content, including curly braces ({, }), newline sequences (\r, \n) and double quotes ("). The goal is to return a string consisting of lines of text which are separated by newline. e. g. setMessage a b c gives a b c setMessage a\nb b c gives a b b c setMessage a\nb gives a b I came up with the following solution: proc setMessage {msg args} { if {[llength $args]} { set all [join [eval list [list $msg] $args] "\n"] } else { set all $msg } return $all } It works with arbitrary and complex strings, even containing braces and such. But... just to know: Is there a simple or more elegant way to join "all"? It's not really important, but I'm just wondering if I hit a good solution... -- Roger Roger J. Meier <r@tac.ch> wrote: > proc setMessage {msg args} { > if {[llength $args]} { > set all [join [eval list [list $msg] $args] "\n"] > } else { > set all $msg > } > return $all > } You want to return a newline delimited string, right? Perhaps: proc setMessage {msg args} { set all $msg if {[llength $args] > 0} { append all \n [join $args \n] } return $all } -- Glenn Jackman NCF Sysadmin glennj@ncf.ca ...

SELECTing WHERE string is within other string
I have column data that looks like this: id | ColumnA ---+----------- 1 | 12,35,123 2 | 1,23 3 | 233,34,35 4 | 34 And I want to be able to make a WHERE clause where I can match up a value to one of the values between the commas. I.e. each of the numbers between the commas are seperate values I wish to compare against. Is there any function, perhaps like VBScripts "Split" function, where I can split those numbers up and compare a value against them? Perhaps there's another answer someone has? Example: If I'm searching with a value of "12" row 1 would be returned. If I'm searching with a value of "35", row 1 and 3 would be returned. -- [ Sugapablo ] [ http://www.sugapablo.com <--music ] [ http://www.sugapablo.net <--personal ] [ sugapablo@12jabber.com <--jabber IM ] You're asking for a query solution to a problem caused by a flawed design. Have you considered changing the design instead? This is much easier: CREATE TABLE Sometable (id INTEGER, col_a INTEGER, PRIMARY KEY (id,col_a)) INSERT INTO Sometable VALUES (1,12) INSERT INTO Sometable VALUES (1,35) INSERT INTO Sometable VALUES (1,123) INSERT INTO Sometable VALUES (2,1) INSERT INTO Sometable VALUES (2,23) INSERT INTO Sometable VALUES (3,233) INSERT INTO Sometable VALUES (3,34) INSERT INTO Sometable VALUES (3,35) INSERT INTO Sometable VALUES (4,34) SELECT id FROM Sometable WHERE col_a = 35 -- David Portas ------------...

String
there is a function that calculate string lenght? how use that? On Wednesday 31 August 2005 18:52 TC wrote: > there is a function that calculate string lenght? 'Length > how use that? Foo : constant String := "bar"; Len : Integer := Foo'Length; -- Len=3 -Frode -- ^ Frode Tenneb� | email: frode@tennebo.com | Frode@IRC ^ | with Standard.Disclaimer; use Standard.Disclaimer; | Frode Tenneb� a �crit : > On Wednesday 31 August 2005 18:52 TC wrote: > > >>there is a function that calculate string lenght? > > 'Length Just to point out that it is called an attribute in Ada. Pascal. -- --|------------------------------------------------------ --| Pascal Obry Team-Ada Member --| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE --|------------------------------------------------------ --| http://www.obry.net --| "The best way to travel is by means of imagination" --| --| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595 Frode Tenneb� wrote: > On Wednesday 31 August 2005 18:52 TC wrote: > >>there is a function that calculate string lenght? > > 'Length > >>how use that? > > Foo : constant String := "bar"; > Len : Integer := Foo'Length; -- Len=3 This is of course correct so long as one is using fully filled-out string values. (Frode, I know you know all of the following, I'm just adding to it for the benef...

no char->string / string-append
Do I have to use make-string to append chars onto the end of strings? A la (string-append "Hello" (make-string 1 #\!)) I suppose the real solution would be to not use string-append at all. Any advice? -- Neil Cerutti Strangely, in slow motion replay, the ball seemed to hang in the air for even longer. --David Acfield In article <slrndtkkud.1pc.leadvoice@FIAD06.norwich.edu>, Neil Cerutti <leadvoice@email.com> wrote: > Do I have to use make-string to append chars onto the end of > strings? A la > > (string-append "Hello" (make-string 1 #\!)) Well, (string-append "Hello" (string #\!)) is marginally simpler. I'm assuming that #\! here really indicates a non-constant character. > I suppose the real solution would be to not use string-append at > all. Any advice? Appending strings is slow. Use string ports (srfi-6) if you have them. Lauri On 2006-01-27, Lauri Alanko <la@iki.fi> wrote: > In article <slrndtkkud.1pc.leadvoice@FIAD06.norwich.edu>, > Neil Cerutti <leadvoice@email.com> wrote: >> Do I have to use make-string to append chars onto the end of >> strings? A la >> >> (string-append "Hello" (make-string 1 #\!)) > > Well, (string-append "Hello" (string #\!)) is marginally simpler. I'm > assuming that #\! here really indicates a non-constant character. > >> I su...

Text string to Hex number string.
4-4-07 In my application I read a string in from a .txt file. The string consist of 8 groups of 2 digits representing hex codes. Like: 0112010208020211. I need to convert this in to hex numbers 01 12 01 02 08 02 02 11 so that I can attach a header and calculate a check sum. When I load 0112010208020211 into a string control set for hex display I get 3031 3132 3031 3032 3038 3032 3032 3131, which is ok because I can add my header and calculate the check sum in this form but how do I get it back to 01 12 01 02 08 02 02 11 form to send to the device under test? Thanks TeBlues &nbsp; &nbsp; &nbsp; sorry my computer freaked out and posted many times <img src="http://forums.ni.com/attachments/ni/170/239858/1/hex_fun.JPG"> Message Edited by James R on 04-04-2007 04:45 PM hex_fun.JPG: http://forums.ni.com/attachments/ni/170/239858/1/hex_fun.JPG ...

convert ascii string to hex string
I'm having trouble converting an&nbsp;ascii string to a hex string&nbsp;and parse.&nbsp;&nbsp;For&nbsp;example, if the input&nbsp;string is EQ36&nbsp;(length = 4) the output string&nbsp;should be 45513336 (length 8).&nbsp; Any suggestions how this conversion&nbsp;can be done?&nbsp; Thanks in advance.&nbsp; Hi, this should do it.<img src="http://forums.ni.com/attachments/ni/170/336134/1/Example_VI.png"> Greets, daveMessage Edited by daveTW on 06-30-2008 02:12 PM Example_VI.png: http://forums.ni.com/attachments/ni/170/336134/1/Example_VI.png If it is only a "display-thing", there is an even simpler solution! Just display the string in a string indicator and set it as "Hex-display"....hope this helps,Norbert Thanks a bunch, worked perfectly! &nbsp; ...

a modified string-to-string correction problem
Hi folks, I'm poring over an interesting problem but maybe someone can give me a pointer to an existing solution. I'd like to replicate changes I made to a sequence in a corresponding (relational, doesn't really matter) database, with a minimum (or approximation thereof) number of queries. That is, more generically, I have a string x = x1 x2 ... xn that corresponds to a sequence of objects in a database. Now the string is modified by some unspecified operation into a string x' that might be missing some symbols from x, might have some extra and might have moved a few around. I'd like to find the shortest (or a good approximation thereof) sequence of edit operations necessary to change x into x'. For now I assume that all the edit operations have the same cost. The String-to-String Correction Problem as described by Wagner and Fischer[1] does this but it uses the operations delete/insert/change (of a symbol) whereas I want to use delete/insert/move, where move can move a symbol in x' from some position i to a position j (0 <= i,j <= |x|). Wagner/Fischer presented a O(n^2) algorithm for their problem but I suspect that including a move operation makes it a lot more difficult, it smells of NP-hardness. Has this already been solved efficiently or maybe for a similar problem? [1] http://portal.acm.org/citation.cfm?coll=GUIDE&dl=GUIDE&id=321811 On Jul 27, 4:16 pm, Matthias Buelow <m...@incubus.de> wrote: > Hi folks, > >...

Search for string and then take string next to it.
Hi, What I'm looking for is a way for php to retrieve a webpage, search for a string in it, and next to that will be a date string in the format (e.g.) 03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time variable (preferably using unix timestamp)... This possible? Thanks, Ben -- BWGames to email change de.news to de-news On Mon, 1 Nov 2004 08:14:58 +0000, BWGames wrote: > Hi, > > What I'm looking for is a way for php to retrieve a webpage, search for a > string in it, and next to that will be a date string in the format (e.g.) > 03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time > variable (preferably using unix timestamp)... > > This possible? > > Thanks, > > Ben Also, the timezone is irrelevant, I just need a way of identifying dd-mm-yy hh:mm:ss as a php date/time stamp to perform time calculations on it... -- BWGames to email change de.news to de-news On Mon, 01 Nov 2004 08:14:58 +0000, BWGames wrote: > What I'm looking for is a way for php to retrieve a webpage, search for a > string in it, and next to that will be a date string in the format (e.g.) > 03-Sep-04 22:37:40 BST, and then I'd like PHP to store that as a date/time > variable (preferably using unix timestamp)... > > This possible? http://www.php.net/strtotime Adam -- Adam Harvey Optimiser Pty Ltd To e-mail: don't make an example out of me! On Mon, 01 Nov 2004 16:...

Strings
Hi there, I have a series of strings that can look like the following: GB/GB/12345 SAL-6589785 JTW/JW-98745621 12G/5P-874562 As you can see the strings all have a number at the end but are all different lengths and formats. How can I step backwards through the string starting at the end and getting all of the numbers in the last portion of the string? -- Allen @ jbex Inflammable material implanted in my head It's a suspect device that's left 2000 dead Look for InstrRev -- Hans Eekels (The Netherlands) "You need at least two colours to see one thing" www.SpecialSoftware.nl "Allen @ jbex" <ats1@takeyourhatoff.ntalk.org> schreef in bericht news:1w4ansg03w8i3$.qfpc8mprvqvy.dlg@40tude.net... > Hi there, > > I have a series of strings that can look like the following: > > GB/GB/12345 > SAL-6589785 > JTW/JW-98745621 > 12G/5P-874562 > > As you can see the strings all have a number at the end but are all > different lengths and formats. How can I step backwards through the string > starting at the end and getting all of the numbers in the last portion of > the string? > -- > Allen @ jbex > > Inflammable material implanted in my head > It's a suspect device that's left 2000 dead Allen @ jbex wrote: > Hi there, > > I have a series of strings that can look like the following: > > GB/GB/12345 > SAL-6589785 > JTW/JW-98745621 > 12G/5P-874562 > > As y...

Converting string to unicode string in T-SQL
Hi, We have stored proc name proc_test(str nvarchar(30)). So far this proc has been invoked from a .NET application assuming that only English character strings will be passed to it. The calls are like proc_test('XYZ') We now have a requirement for passing Chinese strings as well. Rather than changing the calls throughout the application, we would like to handle it in the stored procedure so that it treats the string as a unicode string. Can we apply some function to the parameter to convert it to unicode so that we don't have to call with an N prefixed to the string? Thanks, Yash Please do not multipost (if really necessary, you should cross-post). You have several responses in the other thread: http://groups.google.com/group/microsoft.public.sqlserver.programming/browse_frm/thread/5efe6e494f5d0f8e/# Razvan ...

normal string display to Hex string display
Hi all i like to convert a normal strijng display which contains alphanumeric strings to hex format String length will be of 25 characters which will be read through bar code reader &nbsp; Could&nbsp;someone help me in solving this &nbsp; Thanks &nbsp; Bala I'm not sure I understand what you're asking. Do you want a hex number, or do you want the input string converted to a hex value, and then back to a hex format string, which just gets you back to where you started?For example, if you have the string "A34B", well, that's already in hex "format".Message Edited by smercurio_fc on 06-13-2008 09:35 AM Right click the indicator and select "Hex Display" You know, I though about suggesting this, but then I wasn't sure that's what the user wanted, since that would display the character "A" in its ASCII code, which would be hex 41. Still confused as to what the user wants. My best guess would be data comes in through the barcode scanner and he wants to transmit the hex values over a network or something?&nbsp; maybe a third party dll?&nbsp; in which case, a typecast to U8&nbsp;and number to hex string or something like that would work Or he only wants to display the read string in hex... in which case he only needs to set the format of the indicator to Hex Display... still not shure... hi all thanks for your replies... i will explain my problem again. I am reading a value from a bar code ...

paste a string as a string without evaluating contents
I am pasting data from Excel. In a long list of numbers/letters, I have the string: 1E4. I paste this into a cell array using the variable editor and "paste excel data", and what I get is 10000 because this got interpreted as scientific notation. Caused major headache and lost a lot of time. Is there a way to ensure that things get pasted as strings? I tried pre-defining the array as a cell (b=cell(11000,1)) but that did not prevent the problem. Is there a way to ensure that something is pasted as a string? Thanks! ...

String concatenation in ruby
Hi, This seems to be a basic question but i would like to know why. String concatenation in rails can be done in the following three ways: 1. a+b+c 2. a<<b<<c 3. "#{a}#{b}#{c}" where a b c are three variables Which is the good way to go about concatenation and why? a+b+c is not good because it creates temp string objects i guess But i would really like to know of the three which is better and why. Is there any performance difference in using them Thanks in advance -- Posted via http://www.ruby-forum.com/. On 08/05/2010 06:47 AM, Prachi Tripathi wrote: > Hi, > > This seems to be a basic question but i would like to know why. > > String concatenation in rails can be done in the following three ways: > > 1. a+b+c > 2. a<<b<<c > 3. "#{a}#{b}#{c}" > > where a b c are three variables > > Which is the good way to go about concatenation and why? > > a+b+c is not good because it creates temp string objects i guess > > But i would really like to know of the three which is better and why. Is > there any performance difference in using them > > Thanks in advance > As you mention, using + will create strings which then need to be garbage collected. Using << will modify the left-most variable, which you may not always desire. The other downside to using + or << is that they will raise an error if any of your...

strings and {...}
Is there something build into php where {0} or {1} means something? For example, SELECT * FROM table1 WHERE col1 = {0} AND col2 = {1}; Mike ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- > SELECT * FROM table1 WHERE col1 = {0} AND col2 = {1}; Umm...that's SQL, not PHP. However, PHP does use curly braces for things other than blocks of code: http://www.php.net/manual/en/language.types.string.php One thing they can be used for is addressing strings as if they were arrays. The number inside the {} indicates which character (zero-indexed) you want to get at. So: $s = 'Hello'; $s{0} = 'f'; echo $s; will output 'fello'. "Michael G" <mike-g@montana.com> kirjoitti viestiss�:1126108002_15849@spool6-east.superfeed.net... > Is there something build into php where {0} or {1} means something? > > For example, > > SELECT * FROM table1 WHERE col1 = {0} AND col2 = {1}; > curly braces do have a special meaning inside a string. see php manual chapter on strings, especially the paragraphs about simple syntax and complex (curly) syntax. -- SETI @ Home - Donate your cpu's idle time to science. Further reading at <http://setiweb.ssl.berkeley.edu/> Kimmo Laine <eternal.erectionN0@5P4Mgmail.com> ...

Catching std::strings and c-style strings at once
Hello. Given the following try...catch construct: try { } catch (const string& msg) { } I might be overlooking something basic, but why can't the compiler use one of std::string's constructors in order to match: throw "Something happened!"; The intent is to avoid having to add an extra catch block, i.e.: try { } catch (const string& msg) { } catch (const char* const msg) { } Thank you, -- Ney Andr� de Mello Zunino "Ney Andr� de Mello Zunino" <zunino@inf.ufsc.br> wrote in message news:2vvsg5F2qv3bfU1@uni-berlin.de... > Hello. > > Given the following try...catch construct: > > try > { > } > catch (const string& msg) > { > } > > I might be overlooking something basic, but why can't the compiler use one > of std::string's constructors in order to match: > > throw "Something happened!"; > > The intent is to avoid having to add an extra catch block, i.e.: > > try > { > } > catch (const string& msg) > { > } > catch (const char* const msg) > { > } > > Thank you, It is a bad practice to throw literals. It leads to code like catch(const char *text) { string str(text); if (text == "error1") //... else if (text == "error2") //... else if (text == "error3")//... } "Ney Andr� de Mello Zunino" <zunino@inf.ufsc.br> wrote... > Given the following try...catch co...

removing first occurence of a string in a given string
hi all, is there a way i can identify (to remove) the first occurence of a string in a given string (text variable) i.e. i have values such as 'Block 01' and 'Block 01' --- the 2nd instance has 2 spaces, and i wanna get rid of the first one? thanks On Oct 9, 3:36 pm, "Eversmann Inc." <rifazraz...@gmail.com> wrote: > hi all, > > is there a way i can identify (to remove) the first occurence of a > string in a given string (text variable) > > i.e. > i have values such as 'Block 01' and 'Block 01' --- the 2nd instance > has 2 spaces, and i wanna get rid of the first one? > > thanks TRANWRD does it . thanks Nagakumar Eversmann Inc. wrote: > hi all, > > is there a way i can identify (to remove) the first occurence of a > string in a given string (text variable) > > i.e. > i have values such as 'Block 01' and 'Block 01' --- the 2nd instance > has 2 spaces, and i wanna get rid of the first one? TRANWRD substitutes every occurence of your target with its replacement. PRXCHANGE lets you can control how many times a replacement occurs. -- Richard A. DeVenezia http://www.devenezia.com/ ...

Finding a string match in a cell array of strings
This should be simple but I just have not seemed crack this simple task. I have a cell array of 850 elements lets say.... intermRowIDs = {850,1} Almost all of the elements are strings like the following with multiple words 'C5N Merged Feed Partial Pressure (psig)' 'C6P Merged Feed Partial Pressure (psig)' 'C6N Merged Feed Partial Pressure (psig)' 'C7P Merged Feed Partial Pressure (psig)' 'C7N Merged Feed Partial Pressure (psig)' 'C8P Merged Feed Partial Pressure (psig)' 'C8N Merged Feed Partial Pressure (psig)' But some elements are empty where I get the following answers >>intermRowIDs{850} ans = [] >>intermRowIDs(850) ans = {[]} What I am trying to do is search this array for say "Pressure" or "pressure" and have the indices in intermRowIDs spit out. This way I can use those row values in the corresponding matrix to get the values of those descriptions. I have been playing with 'strcmp' and 'strncmp' combined with 'find' but it does not seem to like '[]' empty fields and only seems to work if what the user is looking for is the first word. 'strfind' does not like the empty values and it is case sensitive. %% Current Work Around %% ---------------------------------------------------------------------------------- clc tic exprs = 'Feed'; index3 = ze...

Count times text string occurs in a text string
I know this is a newb question, but how do you count a text string in a text string? I am looking to count "\" in CStr(fld.Path)? I was working with a function I downloaded called getlen which calls a function strcount, but I butchered it and cannot find the source. Thanks ren ren Try this Function CountSubString(StringIn As String, SubString As String) As Long Dim pos As Long pos = InStr(StringIn, SubString) Do While pos CountSubString = CountSubString + 1 pos = pos + Len(SubString) If pos < Len(StringIn) Then pos = Instr(pos, StringIn, SubString) Else Exit Do End If Loop End Function regards Ian ** invalid e-mail address, change dk to full country name Tips & Tricks - http://tips.kingsoft-denmark.com "renasis" <robertneilmiller@yahoo.com> wrote in message news:1107318695.615695.260960@g14g2000cwa.googlegroups.com... >I know this is a newb question, but how do you count a text string in a > text string? I am looking to count "\" in CStr(fld.Path)? I was working > with a function I downloaded called getlen which calls a function > strcount, but I butchered it and cannot find the source. > > Thanks > > ren > The following simple function will take of this very easily ren: Public Function lCount(sStr As String, sSubStr As String) As Long ' Count occurrences of sSubStr in sStr If Len(sStr) <> 0 Then lCount = (Len(sStr) - Len(Repla...

Re: Using scan from string to convert a string into a number
Hello, &nbsp; May be you can checkout the attached example. &nbsp; Perkash Mohan Lal Institute of Semiconductor Technology Technical University Braunschweig string_conversion_1.vi: http://forums.ni.com/attachments/ni/170/218179/1/string_conversion_1.vi ...

How do I see if one string is found within another string?
Hi, I wonder if anyone can help? How do I see if one string is found within another string? or how many instances of one string, is found within another. ie. a="Sheree smells of poo" b="smells" I'd like a function that would return 1, (for true, or that the word smells, if found once) PHP is ace. There must be a simple way of doing this. I mean, its got loads of useless functions that noones ever going to use. Im sure if PHP has a built-in function to convert hebrew, then Im sure it can do this. Any ideas? Cheers Phil. googlegroups@budget-edi.co.uk wrote: > Hi, I wonder if anyone can help? > > How do I see if one string is found within another string? > or how many instances of one string, is found within another. > > ie. > > a="Sheree smells of poo" > b="smells" > > I'd like a function that would return 1, (for true, or that the word > smells, if found once) > > PHP is ace. There must be a simple way of doing this. I mean, its got > loads of useless functions that noones ever going to use. Im sure if > PHP has a built-in function to convert hebrew, then Im sure it can do > this. Any ideas? > > Cheers > Phil. > Phil, http://www.php.net/manual/en/function.strpos.php Carl. I noticed that Message-ID: <5DbLe.442$k92.260@newssvr19.news.prodigy.com> from Carl contained the following: >> a="Sheree smells of poo" >> b=&q...

Input string -> table -> output string?
I have a nasty situation in SQL Server 7.0. I have a table, in which one column contains a string-delimited list of IDs pointing to another table, called "Ratings" (Ratings is small, containing less than ten values, but is subject to change.) For example: [ratingID/descr] 1/Bronze 2/Silver 3/Gold 4/Platinum When I record rows in my table, they look something like this: [uniqueid/ratingIDs/etc...] 1/2, 4/... 2/null/... 3/1, 2, 3/... My dilemma is that I can't efficiently read rows in my table, match the string of ratingIDs with the values in the Ratings table, and return that in a reasonable fashion to my jsp. My current stored procedure does the following: 1) Query my table with the specified criteria, returning ratingIDs as a column 2) Split the tokens in ratingIDs into a table 3) Join this small table with the Ratings table 4) Use a CURSOR to iterate through the rows and append it to a string 5) Return the string. My query then returns... 1/"Silver, Platinum" 2/"" 3/"Bronze, Silver, Gold" And is easy to output. This is super SLOW! Queries on ~100 rows that took <1 sec now take 12 secs. Should I: a) Create a junction table to store the IDs initially (I didn't think this would be necessary because the Ratings table has so few values) b) Create a stored procedure that does a "SELECT * FROM Ratings," put the ratings in a hashtable/map, and match the values up in Java, since Java is better for string manipulat...

Web resources about - String or string - comp.lang.ruby

Trump’s Call To Punish Women Who Have Abortions Is Way Outside The Mainstream
Donald Trump careened between polar-opposite positions on abortion Wednesday, demonstrating in the space of about 180 minutes the hazards of ...

Key Details in No Charges Against 2 Minneapolis Officers
A Minnesota prosecutor announced Wednesday that two Minneapolis officers would not face charges in the November shooting of a black man

Hans Zimmer Is Done With Superhero Movies; ‘Thor 3’ Might Be Tom Hiddleston’s Last Time as Loki
Superheroes are forever. Even the ones that don’t count immortality among their special powers have a way of surviving, provided they’re popular ...

Foxconn Takes Control of Sharp
Foxconn Technology Group, the world’s largest contract maker of consumer electronics, announced on on Wednesday that they have officially acquired ...

Mississippi Senate About to Vote on ‘Worst Religious Freedom Bill To Date’
Mississippi lawmakers are set to vote today on a ‘religious freedom’ bill that has been called one of the worst pieces of anti-LGBT legislation ...

Star Wars Rebels: The Grand Inquisitor’s Backstory Was Seen in ‘The Clone Wars’
Earlier today we told you how a character created for the Star Wars animated series may have already appeared in one of the original trilogy ...

Are Nick Young & Iggy Azalea Headed for a Breakup After Cheating Rumors?
Nick Young is reportedly doing everything he can to save his relationship with Iggy Azalea – TMZ Inside Lamar Odom ‘s night out at the bar – ...

Leonardo DiCaprio’s Appian Way Signs First-Look Deal With Paramount Pictures
Brad Grey, CEO of Paramount Pictures and Oscar-winning actor Leonardo DiCaprio announced the finalization of a three-year, first-look production ...

Amazon Updates Its Policies To Ban USB Type-C Cables That Are Not Fully Spec Compliant
Ryan Whitwam / Android Police : Amazon Updates Its Policies To Ban USB Type-C Cables That Are Not Fully Spec Compliant — Googler Benson Leung ...

U.N. Urges Countries to Take in 480,000 Syrian Refugees
Secretary General Ban Ki-moon, opening a conference in Geneva, called for “an exponential increase in global solidarity” over the next three ...

Resources last updated: 3/30/2016 11:08:56 PM