我正试图在Excel中使用一种允许我说出
的方法ABC-DEF 与 DEF-ABC
相同任何人都知道如何做到这一点?
答案 0 :(得分:1)
了解如何提问: https://stackoverflow.com/help/how-to-ask
有时,但有时候,(特征是 manchmal aber nur manchmal )你可能会幸运地发布这样的问题得到回答:
Option Explicit
Public Sub TestMe()
Debug.Print CompareMe("ABC-DEF", "DEF-ABC")
Debug.Print CompareMe("ABC-DEF", "DEF-AAC")
End Sub
Public Function CompareMe(strCompareA As String, strCompareB As String, Optional strDelim = "-")
Dim arrA As Variant
Dim arrB As Variant
arrA = Split(strCompareA, strDelim)
arrB = Split(strCompareB, strDelim)
CompareMe = (arrA(0) = arrB(1) And arrA(1) = arrB(0))
End Function
检查TestMe
子,它会在控制台中打印结果。
此外,this is an interview algorithm question, asked by Google。这是一个通用的工作答案 - 反转整个字符串,然后按字分割并反转每个单词。这是如何使用VBA:
Option Explicit
Public Sub TestMe()
Debug.Print strReverseOrder("ABC-DEF-GHI")
Debug.Print strReverseOrder("ABC-DEF") = "DEF-ABC"
End Sub
Public Function strReverseOrder(strToReverse As String, Optional strDelim = "-")
Dim strWorking As String
Dim arrWorking() As String
Dim lngCounter As Long
Dim strAnswer As String
strWorking = StrReverse(strToReverse)
arrWorking = Split(strWorking, strDelim)
For lngCounter = LBound(arrWorking) To UBound(arrWorking)
strAnswer = IIf(lngCounter = LBound(arrWorking), vbNullString, strAnswer & strDelim) & StrReverse(arrWorking(lngCounter))
Next lngCounter
strReverseOrder = strAnswer
End Function
答案 1 :(得分:1)
答案 2 :(得分:0)
以下对我有用:
=IF(D2>H2,CONCATENATE(D2,"-",H2),CONCATENATE(H2,"-",D2))
答案 3 :(得分:-1)
假设A1
这是B1
:=IF(A1="ABC-DEF","DEF-ABC",A1)
。向下拖动以填写。