473,657 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to compare with a word only in a sentence?

170 New Member
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 1428
KevinADC
4,059 Recognized Expert Specialist
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 New Member
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
7753
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 to the wave-file pre-recorded by the teacher, and gives out a score to indicate the similarity between them. This function will help the students pronounce properly, I think. Is there an existing library (C or Python) to do this? Or if someone
2
3333
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 text will be anywhere from a word or two to multiple paragraphs. An example: Original sentence: The brown dog ran outside at night. During the day, the brown dog slept. Updated sentence: The big brown dog ran outside when dark. During...
2
2215
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 the sentence and print it example sentence "hello i am Anouar" the space after hello should not be a problem for the program so whe i ask for the second word it should give "i" for an answer.. this is what i've got so far
1
1389
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 ////////////////////// using System; namespace SimpleMath
2
6019
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 word The code i wrote is like this Dim objword As Word.Application objword = CreateObject("Word.Application") With objword .Documents.Open("C:\Seshu is a bad boy.doc") ...
2
2871
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 please help me.. #include <iostream> using std::cout; using std::cin; using std::endl;
12
13003
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 proteins in controlling beta-F1-ATPase expression."; $word="RNA binding proteins";
1
4342
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 problem is how to write a code using split function to split that sentence into words then print out each word separately. let me give u an example: >>>sentence=" My question is to know how to write a code in Python" then the output of this...
2
1834
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. I would like to establish what error in the code is causing the first word to be mangled. #include<iostream> #include<cstring> #include<cstdlib> using namespace std; int main() { cout<<"Transposing letters in a string \n"; cout<<"Type a...
0
8399
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1959
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.