473,406 Members | 2,620 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,406 software developers and data experts.

how to compare with a word only in a sentence?

170 100+
hi all,

if i got a string say

i feel like going to swim today

if i have input say "swim"

and i wanna compare it with the sentence above, it will return true and go on to the rest of the program

cos normally we do this:

if ( swim eq sentence)

it will be true only if it matches the whole sentence so now i just it to return true as long as the sentence has the word swim and carry on with the program

any way in perl we can do this?
Apr 28 '08 #1
2 1425
KevinADC
4,059 Expert 2GB
use a regexp:

Expand|Select|Wrap|Line Numbers
  1. if ($foo =~ /pattern/) {
  2.    do something;
  3. }
  4.  
  5.  
where $foo is the sentence and pattern is "swim". There are plenty of online resources to guide you with learning regular expressions.
Apr 28 '08 #2
poolboi
170 100+
use a regexp:

Expand|Select|Wrap|Line Numbers
  1. if ($foo =~ /pattern/) {
  2.    do something;
  3. }
  4.  
  5.  
where $foo is the sentence and pattern is "swim". There are plenty of online resources to guide you with learning regular expressions.
thanks a lot once again :)
Apr 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Qiangning Hong | last post by:
I want to make an app to help students study foreign language. I want the following function in it: The student reads a piece of text to the microphone. The software records it and compares it...
2
by: Nathan Rosaaen | last post by:
I want to be able to easily see what changes were made from original to updated sentences (words added/removed/changed). I'm not too concerned about speed, just looking for something. The compared...
2
by: Anouar | last post by:
The point was to make a program that gives you the possibilty to enter a sentence and when you press "enter" it should ask a number for example when i press 4 It should take the 4th word out of...
1
by: smith flyers | last post by:
i got the following error when compiling the codes.. the name 'word' does not exist in the class or namespace 'SimpleMath.Pig' Can anyone troubleshoot on this . Thank you ...
2
seshu
by: seshu | last post by:
Hi Everybody I have a piece of code to compare two documents using vb.net but the problem here is it is comparing the whloe sentence but not word by word how to compare word by...
2
by: valechale | last post by:
I need some serious help!! I am supposed to convert an english sentence to pig latin.... This is what I have so far but everytime I go to compile it it says that word is undeclared!! can someone...
12
by: Archanak | last post by:
Hi, I have a word like this: "Rna binding proteins" and i want to match this exact phrase. I have written code like this: $sentence="Overall, the participation of additional RNA binding...
1
by: fellya | last post by:
Hi, i don't have enough experience in writing codes in Python but now i'm trying to see how i can start using Python. I've tried to write a simple program that can display a sentence. now my...
2
by: whodgson | last post by:
The following code accepts a string from the user and swaps the first and last letters in each word. It prints out the original string incorrectly by dropping off the first letter of the first word....
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.