快速提问,如果我想在第二次出现数字后删除所有内容:
即 -
我有:
1105 Bracket Ave. Suite 531 Touche
5201 Used St. 1351 Bored Today
我想:
1105 Bracket Ave. Suite 531
5201 Used St. 1351
我会用这个简单的公式或VBA吗?
答案 0 :(得分:1)
这是一个使用VBA正则表达式引擎的UDF,用于删除第二个整数之后的所有内容。
Option Explicit
Function FirstTwoNumbers(S As String) As String
Dim RE As Object
Set RE = CreateObject("vbscript.regexp")
With RE
.Pattern = "(\d+\D+\d+).*"
FirstTwoNumbers = .Replace(S, "$1")
End With
End Function
如果只有一个整数,它将返回整个字符串。
如果数字可能是十进制数字,则需要修改.Pattern
这是另一个仅使用本机VBA方法的UDF:
Function FirstTwo(S As String) As String
Dim V
Dim tS As String
Dim I As Long, numNumbers As Long
V = Split(S)
Do Until numNumbers = 2
tS = tS & Space(1) & V(I)
I = I + 1
If IsNumeric(V(I - 1)) Then numNumbers = numNumbers + 1
Loop
FirstTwo = Mid(tS, 2)
End Function
最后,一个没有特别假设的公式:
=LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LOOKUP(2,1/ISNUMBER(-TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),seq))))
seq
和seq99
是命名公式Formula ► Define Name
seq Refers to: =ROW(INDEX($1:$255,1,1):INDEX($1:$255,255,1))
seq_99 Refers to: =IF(ROW(INDEX($1:$255,1,1):INDEX($1:$255,255,1))=1,1,(ROW(INDEX($1:$255,1,1):INDEX($1:$255,255,1))-1)*99)
答案 1 :(得分:0)
这个解决方案有以下假设: -
试试这个: -
` var involvedEmployees = employeeItems.map(employeeItem => {
return new Promise((resolve,reject) => {
employeeId = employeeItem.employeeId;
whatDid = employeeItem.whatDid;
role = employeeItem.role;
employeeModel.findById(employeeId, function(err, findedEmployee){
findedEmployee = findedEmployee.toObject();
findedEmployee["NewField"] = Variable; //this Variable need to come from .map function
resolve(findedEmployee);
});
});
});
var results = Promise.all(involvedEmployees);
results.then(data => {
res.json(data);
});
`
答案 2 :(得分:0)
这是一个VBA方法,修改范围以适应。它将答案放在相邻的列中
Sub x()
Dim oMatches As Object, r As Range
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "\d+"
For Each r In Range("A1:A5")
If .Test(r) Then
Set oMatches = .Execute(r)
If oMatches.Count > 1 Then
r.Offset(, 1).Value = Left(r, oMatches(1).firstindex + oMatches(1).Length)
Else
r.Offset(, 1).Value = r.Value
End If
Else
r.Offset(, 1).Value = r.Value
End If
Next r
End With
End Sub
答案 3 :(得分:0)
如果A1是你的字符串,你可以使用以下公式,在B1写:
=LEFT(A1,MAX(IFERROR(ISNUMBER(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)))*ROW(INDIRECT("1:"&LEN(A1))),0)))
按 Ctrl + Shift + 同时输入数组公式
这将读取字符串的长度并返回最大数字位置(字符串中的最后一个数字)并返回Left()字符串直到此数字