Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
On 28 Dec 2005 11:39:37 -0800, "paulinoluciano"
wrote: 1 lost cut = Cutting the sequence after the first K present in the sequence (The subsequences of this process should be put in C column:: AASSASDKASASDASFAFSASASADK ASASAFPKQREWEAQEOKSPADAOEK OQPPDAOPSKAEPQ AASSASDKASASDASFAFSASASADKASASAFPKQREWEAQEOK SPADAOEKOQPPDAOPSKAEPQ See my other answer. But I did not understand how you obtained the last two lines in the "1 lost cut" sequence. They are identical to the two lines in the "2 lost cut" sequence, so I thought this might be a typo. But perhaps I am missing something? --ron |
#2
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Hi Ron Rosenfeld,
Thank you very much for your help. Could I use your first function as a VBA code? In this second case, is is possible that we have a typo. In this case speak about 1 lost cut means that you will cut the sequence only after the first K appear, never to the first one. But you will have intermediates in such process because you never now where will be performed the first cut. Luciano |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
On 29 Dec 2005 01:26:31 -0800, "paulinoluciano"
wrote: Hi Ron Rosenfeld, Thank you very much for your help. Could I use your first function as a VBA code? Yes, you can. The morefunc.xll add-in functions can be used in VBA by using the RUN method. See HELP for those add-ins for more details. In this second case, is is possible that we have a typo. In this case speak about 1 lost cut means that you will cut the sequence only after the first K appear, never to the first one. But you will have intermediates in such process because you never now where will be performed the first cut. How do you determine, if you specify ONE lost cut, whether the first cut will occur after the SECOND 'K', or after the THIRD 'K', or ??? The formulas assumed that with ONE lost cut, the first cut would occur after the SECOND 'K'. Here is a UDF written in VBA to do the same thing, using the REGEX.MID function from the morefunc.xll add-in. The variables should be self-explanatory. The return value is an array, and the individual components can be obtained using the INDEX worksheet function. e.g. with the sequence stored in A1: =INDEX(SplitK($A$1,0),1) would return the first item in the '0 lost cuts' splitting function). =================================== Option Explicit Function SplitK(ByVal seq As String, LostCut As Long) As Variant Dim i As Long, j As Long Dim KCount As Long Dim Temp() As String If LostCut < 0 Then SplitK = CVErr(xlErrNum) Exit Function End If KCount = Len(seq) - Len(Replace(seq, "K", "")) ReDim Temp(1 To KCount) For i = 1 To KCount Temp(i) = Run([regex.mid], seq, "(\w+?([^FP]K|$)){" & LostCut + 1 & "}", i) Next i SplitK = Temp End Function ========================= This could also be written as a SUB to automatically place the results into specified cells, but it would be less flexible. To write results into columns B, C, D: ===================================== Option Explicit Sub SplitK() Const seq As String = "AASSASDKASASDASFAFSASASADKASASAFPKQREWEAQEOKSPADA OEKOQPPDAOPSKAEPQ" Const MaxLostCuts As Long = 2 Const ResultColumn As Long = 2 'Column B Dim i As Long Dim LostCut As Long Dim KCount As Long Dim Temp() As String KCount = Len(seq) - Len(Replace(seq, "K", "")) ReDim Temp(1 To KCount) For LostCut = 0 To MaxLostCuts For i = 1 To KCount Cells(i, ResultColumn + LostCut) = _ Run([regex.mid], seq, "(\w+?([^FP]K|$)){" & LostCut + 1 & "}", i) Next i Next LostCut End Sub ==================================== --ron |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Hi Ron,
When we are talking about "lost cut" it means that inside the sequence will be present 1 "K" or 2 "K" or 3 "K" that will not detected in order to be cut. Do you understand? Luciano |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
On 29 Dec 2005 05:42:15 -0800, "paulinoluciano"
wrote: Hi Ron, When we are talking about "lost cut" it means that inside the sequence will be present 1 "K" or 2 "K" or 3 "K" that will not detected in order to be cut. Do you understand? Luciano I understood that to mean that if there is ZERO lost cuts then cut after every K (that is not preceded by an FP) if there is ONE lost cut then cut after every second K that is not preceded by an FP if there are TWO lost cuts then cut after every third K that is not preceded by an FP --ron |
#6
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Yes, it is almost this. However, since some cut is performed the
sequence to be considered to serach the next possible cut is the remained subsequence. In such case, it could be expected any place in the text sequence displayng two (or three) K being that the second or third should be at the end of the sequence. Luciano |
#7
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
On 29 Dec 2005 06:34:48 -0800, "paulinoluciano"
wrote: Yes, it is almost this. However, since some cut is performed the sequence to be considered to serach the next possible cut is the remained subsequence. In such case, it could be expected any place in the text sequence displayng two (or three) K being that the second or third should be at the end of the sequence. Luciano I don't understand how what you are writing is different from the results that my algorithm produces. Perhaps if you gave some examples of the results of my formula on a text string vs what you expect to have as a result. For example, with ONE lost cut, and using your original seq, I get: AASSASDKASASDASFAFSASASADK ASASAFPKQREWEAQEOKSPADAOEK OQPPDAOPSKAEPQ There as been ONE cut missed in each string: AASSASDKASASDASFAFSASASADK ^ ASASAFPKQREWEAQEOKSPADAOEK ^^^ ^ OQPPDAOPSKAEPQ ^ The FPK sequence in the second string is also not cut based on your initial specifications. What kind of output are you expecting from this, and why?? --ron |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using Concatenate function to generate text in Text Box | Charts and Charting in Excel | |||
merged cells into one text cell, size varies dependant on text dat | Excel Discussion (Misc queries) | |||
Text shown up in other cells everytime a text is entered in 1 cell | Excel Discussion (Misc queries) | |||
SUMPRODUCT vs Text??? | Excel Worksheet Functions | |||
Read Text File into Excel Using VBA | Excel Discussion (Misc queries) |