Wednesday, March 23, 2011
TCl code to find and reorder chunk of data in string or paragraph
set dataStr "Result*****ADDENDED*****~~My name is sandeep and I am trying to test the system ~~why do not u do it in a fast manner.~~~IMPRESSION:*****ADDENDED*****~~~well i am trying it with different ways.~~~Examination:OCB - complete it as fast as possible asdasd.Result*****ADDENDED*****~~My qqqqname is sandeep and I am trying to test the system ~~why do not u do it in a fast manner.~~~IMPRESSION:*****ADDENDED*****~~~well fff i am trying it with different ways.~~~Examination:OCB - comddddplete it as fast as possible"
set resultStr "Result*****ADDENDED*****"
set examData "~~~Examination"
set imprdata "~~~IMPRESSION:*****ADDENDED*****~~~"
set strLnth [string length $dataStr]
set resLen 23
set startRange 0
set EndRange [expr $startRange + 23 ]
set str0 ""
set resultStartIn $startRange
set finalList ""
while { $EndRange < $strLnth+1 } {
set str1 [string range $dataStr $startRange $EndRange]
if {[string equal $str1 $resultStr]} {
if { $startRange > 0} {
set str0 [string range $dataStr $resultStartIn $startRange-1]
}
set resultStartIn $startRange
set impFlag "Y"
while {[string equal $impFlag "Y"] && $EndRange < $strLnth} {
set startRange [expr $startRange + 1 ]
set EndRange [expr $startRange + 34 ]
set str2 [string range $dataStr $startRange $EndRange]
if { [string equal $str2 $imprdata]} {
set impFlag "N"
set finalResultStr [string range $dataStr $resultStartIn $startRange-1]
set resultStartIn $startRange
set examFlag "Y"
while {[string equal $examFlag "Y"] && $EndRange < $strLnth} {
set startRange [expr $startRange + 1 ]
set EndRange [expr $startRange + 13 ]
set str3 [string range $dataStr $startRange $EndRange]
if { [string equal $str3 $examData]} {
set examFlag "N"
set finalImpressionStr [string range $dataStr $resultStartIn $startRange-1]
set resultStartIn $startRange
set finalList [concat $finalList $str0]
set finalList [concat $finalList $finalImpressionStr]
set finalList [concat $finalList $finalResultStr]
}
}
}
}
}
set startRange [expr $startRange +1 ]
set EndRange [expr $startRange + 23 ]
}
set str0 [string range $dataStr $resultStartIn $strLnth-1]
set finalList [concat $finalList $str0]
puts $finalList
Subscribe to:
Posts (Atom)