从字符串中间删除文本 - 在Access中 [英] Removing text from the middle of a string - in Access

查看:84
本文介绍了从字符串中间删除文本 - 在Access中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的字符串值如下:

RM - B08 - (1510)EXTERNAL

IRMM - D01 - (M21305)管理

RM - B03 - (S-1120)训练

IES - H02 - (A24007)AIR

IET - F06 - (A13102 / A13111 / A13206)能源技术

如何删除括号括起的中间代码 - 使用Access?

解决方案

goodaan

欢迎到Bytes.com。

我们通常不会在bytes.com上发布代码片段,除非它真的很难或不相同,我们会尝试为解决方案提供指导因为每个用户的体验和情况都是独特的。


在你的情况下,一些建议作为起点,因为你有一个变量字符串:


一种方法是:

+两次调用 InSt r函数,一次找到左括号,一次找到右括号。

+既然您有所需文本的位置,您可以计算文本的长度,然后使用 midstr函数将该文本复制到变量。

+ 替换功能替换为您选择的字符串。

另一种方法,< blockquote>再次使用InStr函数返回括号的位置, len功能以及左功能右函数返回括号组两侧的字符串并连接字符串。

还有第三种方法,

使用for-next循环(或即使是一个do-until-loop相同的概念,但是我会看到两个实现DoUntilLoop和LEN()的方法,使用Mid(),通过原始字符串,将值连接到a保持字符串直到返回的字符是开括号,然后跳过连接它和后续字符,直到紧密括号然后将余数的值连接到保持字符串,最后返回保持字符串

这些只是前三个方法在我的脑海中


如果您要设计代码,请查看 基本的故障排除步骤(在此处阅读)然后 - 如果你还在没有获得所需的结果 - 回复你的脚本并描述正在发生的事情我们可以帮助你微调脚本。


也只是一些语义;但是,如果我们都为某些事情使用相同的名称会有所帮助:

是圆括号
[ ] 是括号
{ } 是大括号


感谢您的建议。我会试试第一和第一第二种方法。我会记住这些名字(我通常会说括号的括号,括号的方括号)。问候


想到另一种方法

使用拆分功能

拆分打开括号

这将给你一个数组:

A()= [RM - B08 - ] [1510] EXTERNAL]

然后将A(1)输入到关闭时的分割括号再次得到:

B()= [1510] [外部]

现在连接A(0)和B(1):

RM - B08 - EXTERNAL

您可能必须使用其中一个修剪函数以删除多余的空格


I have string values as follows:
RM - B08 - (1510) EXTERNAL
IRMM - D01 - (M21305) MANAGEMENT
RM - B03 - (S-1120) TRAINING
IES - H02 - (A24007) AIR
IET - F06 - (A13102 / A13111 / A13206) ENERGY TECHNOLOGY

How can I remove the middle code surrounded by brackets - using Access?

解决方案

goodaan
Welcome to Bytes.com.
We don''t normally start out by posting code snippets here at bytes.com unless it''s something really difficult or unique instead, we try to provide guidance to the solution as each user''s experience and situation is unique.

In your case a few suggestions as starting points, because you have a variable string:

One approach is to:

+ Two calls to InStr Function, once to find the open parenthesis, once to find the close parenthesis.
+ Now that you have position if the desired text, you can calculate the length of the text and then use the midstr function to copy that text to a variable.
+ Replace Function to replace with a string of your choice.

Another method,

Once again, use the InStr function to return the positions of the parenthesis, the len function along with left function and right function to return the strings on either side of the parenthesis group and concatenate the strings.

Yet a third method,

Using a for-next loop (or even a do-until-loop same concept however one would have a little different logic and I see two methods for implementing the DoUntilLoop) and the LEN(), using the Mid(), step thru the original string, concatenate the value to a holding string until the character returned is the open parenthesis then skip concatenating it and subsequent characters until the close parenthesis then concatenate the value of the remainder to the holding string finally returning the holding string

These are just the first three methods "off the top of my head"

If you will design your code, review the basic troubleshooting steps (read here), and then - if you are still not obtaining the desired results - post back your script with a description of what is happening we can help you fine-tune the script.

also just a bit of semantics; however, it helps if we all use the same names for some things:

( ) are Parentheses
[ ] are Brackets
{ } are Braces


thank you for your suggestions. I will try the 1st & 2nd method. And I will keep in mind the names (I usually say brackets for parentheses, square brackets for brackets). Regards


Just thought of another method
Using the split function
Split on the Open Parentheses
This will give you one array:
A()=[RM - B08 - ][1510) EXTERNAL]
Then feed A(1) to the split on the close Parentheses again to get:
B()=[1510][ EXTERNAL]
Now concatenate A(0) and B(1):
"RM - B08 - EXTERNAL"
You may have to use one of the trim functions to remove extra spaces


这篇关于从字符串中间删除文本 - 在Access中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆