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? 5 1620
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?
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
I'm starting to envy others having that
FN capability. Unfortunately, it does
not appear to be in Access 97.
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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,...
|
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...
|
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...
|
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.
|
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
| |
by: Sidhu |
last post by:
Hoe to relplace the word in sentence? Can any one send program?
|
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);
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |