How can I replace or delete a substring in a string?

156 views
Skip to first unread message

Rodrigo Zanatta Silva

unread,
Feb 7, 2018, 12:34:53 PM2/7/18
to mvd...@googlegroups.com
I have a variable with a string:

example = "This is an example."

How can I replace all space with underscore "_"? The most obvious function was the basic.replace. But, it look like to replace the string itself. I didn't understand how to use it. How can I use it?

So the result I want is:

result = "This_is_an_example."

Another example with substring:

result1 = "This<space>is<space>an<space>exemple".

Or even delete the string:

result2 = "Thisisanexample."

What function I use to have this result?

Steve Douglas

unread,
Feb 7, 2018, 12:39:33 PM2/7/18
to Pick and MultiValue Databases
I don't know what environment you are in but in D3 and Universe you can use the CONVERT function for this.

CONVERT "_" to " " IN RESULT

There are other ways I am sure.

Steve Douglas

Steve Trimble

unread,
Feb 7, 2018, 12:40:16 PM2/7/18
to mvd...@googlegroups.com
CONVERT " " TO "_" IN RESULT

or

RESULT = SWAP(RESULT," ","_")


Steve Trimble
Computerized Data Mgmt Inc
(501) 772-3450 cell / text

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+unsubscribe@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms

Steve Trimble

unread,
Feb 7, 2018, 12:42:01 PM2/7/18
to mvd...@googlegroups.com
IF you want to remove 'spaces' you can:
CONVERT " " TO '' IN RESULT
or
RESULT = SWAP(RESULT," ",'')



Steve Trimble
Computerized Data Mgmt Inc
(501) 772-3450 cell / text

On Wed, Feb 7, 2018 at 11:20 AM, Rodrigo Zanatta Silva <rodrigoza...@gmail.com> wrote:

--

Rodrigo Zanatta Silva

unread,
Feb 7, 2018, 1:01:05 PM2/7/18
to mvd...@googlegroups.com
Lol, thanks all.

The function name is swap or the convert. Very easy now. 

Kevin Powick

unread,
Feb 7, 2018, 1:03:34 PM2/7/18
to Pick and MultiValue Databases


On Wednesday, 7 February 2018 12:34:53 UTC-5, Rodrigo Zanatta Silva wrote:
So the result I want is:

result = "This_is_an_example."


Others have mentioned CONVERT and SWAP.  Also look at CHANGE, which may be required if converting From/To string fragments of differing lengths.  e.g. Converting all occurrences of "AB" to "A".


Or even delete the string:

result2 = "Thisisanexample."


To remove all occurrences of a specific character, you could also use TRIM() with the "A" parameter.  e.g. result = TRIM(MyString," ","A").  This Trims (removes) all spaces from the string, MyString.

--
Kevin Powick  

 

George Gallen

unread,
Feb 7, 2018, 1:56:12 PM2/7/18
to mvd...@googlegroups.com

You can use CONVERT only if the substring is 1 character long,


I usually use CHANGE( "this is a test","is","was")

will change this is a test to thwas was a test


And CHANGE will allow replaceing one string that is a different length, so "FOUR" can be changed to "SIX"


I think most of the PICKS have CHANGE




From: mvd...@googlegroups.com <mvd...@googlegroups.com> on behalf of Rodrigo Zanatta Silva <rodrigoza...@gmail.com>
Sent: Wednesday, February 7, 2018 12:20 PM
To: mvd...@googlegroups.com
Subject: [mvdbms] How can I replace or delete a substring in a string?
 
--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com

Tony Gravagno

unread,
Feb 7, 2018, 2:50:39 PM2/7/18
to Pick and MultiValue Databases
Yes, my rule of thumb:
- Use the Convert _statement_ for one character.
- Use the Change _function_ for more than one.
- I used to use Swap, which is in D3, but since all other platforms use Change, I've since, um, changed to Change.
YMMV

@Rodrigo, look in the docs for string manipulation. There are some neat functions in there.
Not related to D3 but QM has some great string and dynamic array manipulation too, of course different from D3. :(

T

Dick Thiot

unread,
Feb 7, 2018, 4:47:45 PM2/7/18
to mvd...@googlegroups.com
Did we establish the the OP was D3?

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+unsubscribe@googlegroups.com

Dan Ell

unread,
Feb 7, 2018, 5:19:44 PM2/7/18
to mvd...@googlegroups.com, Dan Ell

You can use CONVERT only if the substring is 1 character long, though true is a little miss leading.

 

CONVERT can be multiple characters as well, it is just a one for one whereas CHANGE is by word

 

For Prime, Universe and Unidata, A = CONVERT(A,”ABCDE”,”12345”) will convert A to 1 and B to 2 and C to 3 and D to 4 and E to 5, just not ONLY the complete word “ABCDE” to “12345”  Others the syntax would be A = CONVERT(“ABCDE”,”12345”,A).

 

I prefer the statement over the function  CONVERT “ABCDE” TO “12345” IN A, but not all MV platforms support that.

 

jBASE
Dan Ell
jBASE Technical Engineer
949-383-2429
 | 
866‑582‑8447
da...@jbase.com
 | 
www.jbase.com
9245 Research Drive
Irvine
92618
Zumasys
 From: mvd...@googlegroups.com [mailto:mvd...@googlegroups.com] On Behalf Of Tony Gravagno
Sent: Wednesday, February 7, 2018 2:51 PM
To: Pick and MultiValue Databases <mvd...@googlegroups.com>
Subject: Re: [mvdbms] How can I replace or delete a substring in a string?

--

Martin Phillips

unread,
Feb 8, 2018, 4:56:51 AM2/8/18
to mvd...@googlegroups.com

The EREPLACE() function should do what you want with substrings of any length.

 

 

Martin Phillips
Ladybridge Systems Ltd
17b Coldstream Lane, Hardingstone, Northampton NN4 6DB, England
+44 (0)1604-709200

 

 

 

From: mvd...@googlegroups.com [mailto:mvd...@googlegroups.com] On Behalf Of Steve Douglas


Sent: 07 February 2018 17:40
To: Pick and MultiValue Databases

--

Tony Gravagno

unread,
Feb 8, 2018, 2:37:12 PM2/8/18
to Pick and MultiValue Databases
I believe he did say so in another thread.

Cleber Vieira Baptista

unread,
Feb 8, 2018, 5:30:43 PM2/8/18
to mvd...@googlegroups.com

If you want to remove all spaces from the front and back of field 1, you could do

 

   UPDATE.RECORD filename ALL 1,EVAL “TRIM(@RECORD<1>)”


Cleber



Livre de vírus. www.avast.com.

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+unsubscribe@googlegroups.com

For more options, visit http://groups.google.com/group/mvdbms



--
Cleber Vieira Baptista

+55
 61 8441-1663 Oi
 

chandru murthi

unread,
Feb 13, 2018, 10:26:10 AM2/13/18
to Pick and MultiValue Databases

>   UPDATE.RECORD filename ALL 1,EVAL “TRIM(@RECORD<1>)”

Late to this party, but what benighted system's syntax is that?!  I've seen neither UPDATE.RECORD nor EVAL in BASIC (it's a retrieval function.)


On Thursday, February 8, 2018 at 5:30:43 PM UTC-5, Cleber wrote:

If you want to remove all spaces from the front and back of field 1, you could do

 

   UPDATE.RECORD filename ALL 1,EVAL “TRIM(@RECORD<1>)”


Cleber



Livre de vírus. www.avast.com.
2018-02-07 15:20 GMT-02:00 Rodrigo Zanatta Silva <rodrigoza...@gmail.com>:
I have a variable with a string:

example = "This is an example."

How can I replace all space with underscore "_"? The most obvious function was the basic.replace. But, it look like to replace the string itself. I didn't understand how to use it. How can I use it?

So the result I want is:

result = "This_is_an_example."

Another example with substring:

result1 = "This<space>is<space>an<space>exemple".

Or even delete the string:

result2 = "Thisisanexample."

What function I use to have this result?

--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com

For more options, visit http://groups.google.com/group/mvdbms

Martin Phillips

unread,
Feb 13, 2018, 11:19:09 AM2/13/18
to mvd...@googlegroups.com

Hi Chandru,

 

Although I think that Cleber's response to the original posting mis-understood the requirement and has been followed by a variety of alternative solutions, you asked about UPDATE.RECORD…

 

The UPDATE.RECORD command originated in Prime Information and allowed updates to selected records or all records in a file from the command line. For example, you could give everyone a 10% pay rise (nice!) with something like

   UPDATE.RECORD  PAYROLL  ALL  SALARY, EVAL "SALARY * 1.1"

where the qualifying information to the command is the file name, record id(s) or ALL, name or position of the field to be updated and new value which, in this case, is an evaluated expression.

 

UPDATE.RECORD was carried forward into PI/open but was missing from UniVerse. I recall being at a VMark user group meeting many years ago when the lack of this useful command was raised. Because at that time VMark didn't give the impression that it would be added anytime soon, we (Ladybridge Systems) took the version that has always been part of QM and added it to our UniVerse Toolkit which was used by a good number of UV sites in the UK. Our version extended the command to have a "visual mode" but that takes us down a whole new path that we probably don't need to explore in answering your question.

 

I forget exactly when it happened, but somewhere along the way, UPDATE.RECORD was added to UV. Looking at the source code in the APP.PROGS file suggests that this was done by Informix in 2000. For some reason, the relevant VOC item was only added in the Information flavour of UV and the command also appears to be undocumented.

 

 

Martin Phillips
Ladybridge Systems Ltd
17b Coldstream Lane, Hardingstone, Northampton NN4 6DB, England
+44 (0)1604-709200

 

 

 

From: mvd...@googlegroups.com [mailto:mvd...@googlegroups.com] On Behalf Of chandru murthi


Sent: 13 February 2018 15:26
To: Pick and MultiValue Databases

Subject: Re: [mvdbms] How can I replace or delete a substring in a string?


>   UPDATE.RECORD filename ALL 1,EVAL “TRIM(@RECORD<1>)”

Late to this party, but what benighted system's syntax is that?!  I've seen neither UPDATE.RECORD nor EVAL in BASIC (it's a retrieval function.)

On Thursday, February 8, 2018 at 5:30:43 PM UTC-5, Cleber wrote:

If you want to remove all spaces from the front and back of field 1, you could do

 

   UPDATE.RECORD filename ALL 1,EVAL “TRIM(@RECORD<1>)”

 

Cleber

 

 

Image removed by sender.

Livre de vírus. www.avast.com.

image001.jpg

Peter McMurray

unread,
Feb 13, 2018, 3:50:02 PM2/13/18
to Pick and MultiValue Databases
UPDATE.RECORD  AArrrrggghh! The UPDATE verb was the worst idea that Dick ever had. It was simply UPDATE in the original Reality code - I started on Reality 2.4D - It renders a safe user-friendly report environment totally disastrous. I cannot for the life of me see why anybody would put it back. There is no database cross validation of what is happening. Any clown can just crash the system irretrievably - and yes there are plenty of them in the user arena, plus a few programmers I have met. We actually used to rename ED where the half-educated users were around. A few days course on ENGLISH without UPDATE was perfect for them.
If a knowledgeable person needs it then the P commands in ED are excellent however I would always go for Basic in the scenario presented. In fact the storage of transactions in an attribute in an item, particularly at the end of an attribute, is the sort of "bright" idea that caused numerous crashes in the early days. Anyone remember AWA's client DATAMAIL. The whole idea of an attribute is that it contains Like elements not a bundle of disparate elements. Plus putting the most recent at the end instead of the beginning simply extends the tragedy. 
Reply all
Reply to author
Forward
0 new messages