#Include "window9.bi"

Function ClearString(ByREf sText As String, ByREF sTrimSimbols As String = " ") As String Export
	
	dim as string sRet

	dim as long iLenText = len(sText) , _
	iLenTrimSimbols = len(sTrimSimbols) , iResult , iIndex
	
	if iLenText = 0 orelse iLenTrimSimbols = 0 then return ""
	
	dim as wstring ptr pWstrText = allocate((len(sText)+1)*sizeof(wstring))
	
	dim as wstring ptr pWstrTrimSimbols = allocate((len(sTrimSimbols)+1)*sizeof(wstring))
	
	if pWstrText = 0 orelse pWstrTrimSimbols = 0 then
		
		print "Allocated memory error in ClearString!"
		
		return ""
		
	EndIf
	
	*pWstrText = wstr(sText)
	
	*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
	
	deallocate(pWstrText)
	
	deallocate(pWstrTrimSimbols)
	
	return sRet
	
End Function
