473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Idea: Retrieve a Word from a string using one of the letters in that word

I have tried several time to do this but have been unsucessful.
I tried something like:

myFunction(char ater)

str=frm.s1.valu e
sb1=str.substri ng(0,charater)
sb2=str.substri ng(charater,str .length)
//looping function to find nearest space on left side
for(parameters) {
sbs1=str.indexO f(' ')
}
//found the space on the right no problem
sb2=str.indexOf (' ')

this is about as far as i got. Anyone that can help?

Best Regards,
Sandfordc
www.JavaScript-Central.tk

Jul 23 '05
11 2023
Lasse Reichstein Nielsen wrote:
"Random" <ra*******@gmai l.com> writes:
I just assumed \b\S* would provide the closest thing to the behavior he
expected, because the \b would handle some punctuation. But I agree
about \w.


It's also worth remembering that \b is defined in terms of "word
characters" (\b matches a zero-width position where there is a word
character on one side and not the other), and \w matches exactly a
word character, so
"\\b\\w*" + Char + "\\w*\b"
should match a word containing the Char (assuming that Char contains
a word character. If it isn't, then it might need to be escaped,
something like:

"\\b\\w*" + (/^\w$/.test(Char) ? Char : "\\"+Char) + "\\w*\b"

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'


Excellent points.

Curious, I checked it out. In my example of leftWordfromCha r():
Checking For Gave
test e test
test ing e test
test, ing e test
test!ing e test!ing
test! ing e test
test,ing e test,ing
test-ing e test-ing
-test- e test
_test_ e _test_
,test, e test
t(es)t-ing e t(es)t-ing
test ing \s test ing
test\ning \n test\ning (where \n = newline in all three)
test\ning \\n test\ning (where \n = newline in Checking and
Gave)

-- which made me realise that I didn't bother to check whether Char is
actually a single character. Guess I should have called it
leftWordfromStr ing.

Points being: some unpredictable behaviour may result, at the expense
of a broader definition of a 'word', something I probably should have
noted; escaping should be added if it is desired, something I
definitely should have pointed out.

Perhaps a better definition of a 'word' would be:
\w*(\w+[-']{1})*\w+

That would expand the definition of a 'word' to include contractions
and complex words (hyphenated), but would also match substrings
containing (but not terminated by) multiple non-sequential apostrophes.
In some cases, words may also begin or end with apostrophes ('Tis,
'til, an', et cetera) to indicate truncation-- this RE wouldn't match
the apostrophe. I don't think that last one can be accounted for.

Jul 23 '05 #11
Random wrote:
Perhaps a better definition of a 'word' would be:
\w*(\w+[-']{1})*\w+


The {1} is redundant.

Jul 23 '05 #12

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

Similar topics

5
7650
by: jester.dev | last post by:
Hello, I'm learning Python from Python Bible, and having some problems with this code below. When I run it, I get nothing. It should open the file poem.txt (which exists in the current directory) and count number of times any given word appears in the text. #!/usr/bin/python
10
3881
by: Case Nelson | last post by:
Hi there I've just been playing around with some python code and I've got a fun little optimization problem I could use some help with. Basically, the program needs to take in a random list of no more than 10 letters, and find all possible mutations that match a word in my dictionary (80k words). However a wildcard letter '?' is also an acceptable character which increases the worst case time significantly. So if the letters are check...
13
6374
by: Nige | last post by:
To save me re-inventing the wheel, does anyone have a function to capitalise each word in form data? I was thinking along the lines of capitalise the first letter of the string, then any other letter after a space or hyphen. So many users seem to think that just because they are online they can use names like "mr john smith" and so I have to manually change them. --
3
6014
by: gdogg1587 | last post by:
Greetings. I'm working on a program that will "descramble" words. Think of a word scramble game where there is a list of characters, and several blank spaces to denote the word(s) that you are to come up with from the list. i.e.(* denotes a space): _ _ _ _ _ * _ _ _ _ _ _ characters: .hwodlelrlo answer: hello world.
5
1748
by: JrMc | last post by:
I am new to this .net environement. I'm needing to do a simple task - I need to read the first character of a word and replace it with an uppercase. Example: "horse" --> change to "Horse" I can do this on an as/400 using RPG, but cannot figure out the syntax to do it in .net with the .substring and .toupper methods. --
2
13529
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a template file containing the field names Line1 thru Line5 for each record to be printed. If a...
0
1713
by: raypjr | last post by:
Hi everyone. I need a little help with some parts of a word guessing game I'm working on. I have some parts done but unsure about others and could use a little advice. Any help is very much appreciated.Here is the code to give more detail: Dim GameOver As Boolean Dim NumWords As Integer, ThreeWordList(1000) As String, ThreeWordMeaning(1000) As String Dim R As Integer, WordsLeft(1000) As Integer Dim SecretWord As String,...
4
12437
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
2
1839
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
8674
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
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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...
1
8895
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
8861
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
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.