#include once "window9.bi"

Function ClearString(ByREf sText As USTRING, ByREF sTrimSimbols As USTRING = " ") As USTRING Export
	
	dim as USTRING sRet
	
	dim as long iLenText = len(sText) , _
	iLenTrimSimbols = len(sTrimSimbols) , iResult , iIndex
	
	if iLenText = 0 orelse iLenTrimSimbols = 0 then return sRet
	
	dim as wstring ptr pWstrText = allocate((len(sText)+1)*sizeof(wstring))
	
	if pWstrText = 0 then return sRet
	
	#ifdef UNICODE
		*pWstrText = **sText
	#else	
		*pWstrText = wstr(sText)
	#EndIf
	
	dim as wstring ptr pWstrTrimSimbols = allocate((len(sTrimSimbols)+1)*sizeof(wstring))
	
	if pWstrTrimSimbols then
		
		*pWstrTrimSimbols = wstr(sTrimSimbols)
		
		iLenText = len(*pWstrText)
		
		iLenTrimSimbols = len(*pWstrTrimSimbols)
		
		for i as Long = 0 to iLenText-1
			
			for j as Long = 0 to iLenTrimSimbols
				
				if (*pWstrText)[i] = (*pWstrTrimSimbols)[j] then
					
					iResult = 1
					
				EndIf
				
			Next
			
			if iResult then
				
				iResult = 0
				
			else
				
				(*pWstrText)[iIndex] = (*pWstrText)[i]
				
				iIndex += 1
				
			EndIf
			
		Next
		
		(*pWstrText)[iIndex] = 0
		
		sRet = *pWstrText
		
	endif
	
	deallocate(pWstrText)
	
	deallocate(pWstrTrimSimbols)
	
	return sRet
	
End Function

