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

Home Posts Topics Members FAQ

What's the easiest way to change a sentence consisting of 3-7 words into a string in which the spaces have been replaced with the plus sign (+) ?

MLH
Suppose I have a sentence like "One Two Three Four"
and I want it to say "One+Two+Three+ Four". Taking
into account that there might be more than a single
space separating the words sometimes.

Is this fairly easy to accomplish within code?
Nov 13 '05 #1
5 1620
MLH
I found this code...

Do While (InStr(strSourc e, " "))
' if true, the string still contains double spaces,
' replace with single space
strSource = Replace(strSour ce, " ", " ")
Loop

But I can't find information on the Replace
command. Is there one?
Nov 13 '05 #2
Depending on the version of Access you have, you might care to look up
the "Replace" function:

Returns a string in which a specified substring has been replaced with
another substring a specified number of times.

Syntax

Replace(express ion, find, replace[, start[, count[, compare]]])

In your case:

Replace("One Two Three Four", "", "+")

Otherwise you'll have to do what we all did in the bad old days and
roll your own using the "Mid" or "InStr" functions. Not difficult.
Just boring.

Edward

Nov 13 '05 #3
MLH
I'm starting to envy others having that
FN capability. Unfortunately, it does
not appear to be in Access 97.
Nov 13 '05 #4
On Mon, 23 May 2005 11:56:04 -0400, MLH wrote:
I'm starting to envy others having that
FN capability. Unfortunately, it does
not appear to be in Access 97.


You can use the following User Defined function in any version of
Access. It will remove all spaces between words and add the + sign.

Copy the following code to a module:

Public Function InsertPlus(strI n As String) As String

Dim intX As Integer
Dim strNew As String
Dim strNext As String
strNext = strIn
intX = InStr(strIn, " ")
Do While intX <> 0
strNew = strNew & Left(strNext, intX - 1) & "+"
strNext = LTrim(Mid(strNe xt, intX))
intX = InStr(strNext, " ")
Loop
strNew = strNew & strNext
InsertPlus = strNew

End Function

Call it from a query:
NewText:InsertP lus([FieldName])

Filter out Nulls and add error handling as needed.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #5
Pop this code (from Joe Foster) into a module somewhere. It works
perfectly, and some people have reported it's even faster then VBA's
own Replace function. (I find myself still using it in A2K3
applications!)

Public Function JoeReplace(ByVa l Expression As String, _
ByVal Find As String, _
ByVal Repl As String, _
Optional ByVal Start As Long = 1, _
Optional ByVal Count As Long = -1 _
) As String

If Start < 1 Or Count < -1 Then
Err.Raise 5
ElseIf Start > Len(Expression) Then
' nothing to do!
Exit Function
ElseIf Len(Find) < 1 Or Count = 0 Then
If Start <> 1 Then JoeReplace = Mid$(Expression , Start) _
Else JoeReplace = Expression
Exit Function
End If

Dim p As Long, Q As Long, rlen As Long
p = Start
Do
Q = InStr(p, Expression, Find) ', jCompare)
If Q = 0 Then Exit Do

If rlen + Q - p + Len(Repl) > Len(JoeReplace) Then
JoeReplace = JoeReplace & JoeReplace & Space$(Q - p + Len(Repl))
End If

If p < Q Then Mid$(JoeReplace , rlen + 1) = Mid$(Expression , p, Q -
p)
If Len(Repl) Then Mid$(JoeReplace , rlen + Q - p + 1) = Repl

Count = Count - 1
rlen = rlen + Q - p + Len(Repl)
p = Q + Len(Find)
Loop Until Count = 0
JoeReplace = Left$(JoeReplac e, rlen) & Mid$(Expression , p)
End Function

Nov 13 '05 #6

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

Similar topics

137
7059
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very pragmatic - 3) I usually move forward when I get the gut feeling I am correct - 4) Most likely because of 1), I usually do not manage to fully explain 3) when it comes true. - 5) I have developed for many years (>18) in many different environments,...
4
4112
by: r0adh0g | last post by:
I am attempting to build a primitive search form on my site. It is searching an Access Database Table and comparing on field in the database to a field passed from the form. Works great if only one word is keyed in. If two words are keyed in, it separates them with a plus sign. I have tried using the split command to parse out the data but that function does not recognize the plus sign. Any help here? I know some of you folks have...
4
2609
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an QA tested for a new year release. I don't think that going to prove practical, but there is no harm in trying :) and some serious family commitments. But it has to be done soon so this is stage one. Mike Winter provided an extensive list of...
8
13016
by: werner | last post by:
Hi! I don't want to use eval() in order to parse a user-supplied formula. What alternatives do I have? PHP has no standard functionality for tokenizing or parsing expressions in this regard. Here is a simple example: The user supplies the following formula in string format, "a = (6+10)/4", and the script needs to find out what the value of 'a' is.
669
25859
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
10
2082
by: Sidhu | last post by:
Hoe to relplace the word in sentence? Can any one send program?
15
9022
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str, &endptr, 10); printf("errno=%d\n", errno);
3
5599
by: dalearyous | last post by:
ok basically i need to write a program that will replace normal words in a sentence with pirate words. the trick is it needs to be able to take two word phrases. i went about this two different ways: 2d array and hashmap. both have the problem of translating a phrase with two words. im running out of time and need help bad. HASHMAP WAY: import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.awt.*; import...
1
2394
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be great. I know its sorta long, but maybe you only have to few the first few paragraphs. Problem: Write a program in C that generates number palindromes using the algorithm below (see 3. on the next page) and allows the user to try this...
0
8411
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8838
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
8513
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
7351
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 projectplanning, coding, testing, and deploymentwithout 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
6176
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
5638
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.