Import Double quotes within Double Quotes

ADJob mats at adjob.se
Mon Dec 15 05:01:23 EST 2014


Hi all,

The challenge:

Example string: This import "string contaning ”within quotes” etc” and so on

The spaces should be replaced with kTab (tabulator) outside the quotes and kSp (space) within the double quotes:

This(kTab)import(kTab)string(kSp)containg(kSp)text(kSp)”within(kSp)quotes”(kSp)etc(kTab)and(kTab)so(kTab)on(kCr)

So far i have managed to do this in a slow way looping character by character:

For lv_POS from 1 to len(lv_STRING) step 1
	If mid(lv_STRING;lv_POS;1)=kDq     ;; turn on and off the kTab - start and end of kDq
		Calculate lv_kDq as pick(lv_kDq;kTrue;kFalse)
	End If
	If lv_kDq=kFalse
		If mid(lv_STRING;lv_POS;1)=kSp
			Calculate lv_STRING as con(mid(lv_STRING;1;lv_POS-1);kTab;mid(lv_STRING;lv_POS+1;len(lv_STRING)))
		End If
	End If
End For 

There is two problems. This is slow and it does not work if there is quotes within quotes.

Question: Is there a way to detect the difference between this two strings?

string 1 text outside ”text inside ”and within inside” inside quotes”
string 2 text outside ”text inside” and the second "inside quotes”

I have tried with strtok() that is faster, but the embedded double quotes is not detected in a correct way.

Thanks in advance for any clue,

Mats


More information about the omnisdev-en mailing list