⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringoperations.asp

📁 javasrcipt编写的Ajax的类库
💻 ASP
📖 第 1 页 / 共 3 页
字号:
		tmp = replace(val, chr(39), "\'")
		tmp = replace(tmp, chr(34), """)
		tmp = replace(tmp, chr(13), "<br>")
		tmp = replace(tmp, chr(10), " ")
		JSEncode = tmp
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	generates a hidden input field and returns the HTML for it
	'' @DESCRITPION:	its recommended to use this function. e.g. value is HTMLEncoded.
	'' @PARAM:			name [string]: the name of the value
	'' @PARAM:			value [string]: the value it should hold
	'******************************************************************************************************************
	public function getHiddenInput(name, value)
		getHiddenInput = "<input type=""Hidden"" name=""" & name & """ value=""" & HTMLEncode(value) & """>"
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	writes a value to the output and stops the response.
	'' @DESCRIPTION:	The response will be stopped after writing the value. good for debuging.
	'' @PARAM:			value [string]: the value you want to write
	'******************************************************************************************************************
	public function writeEnd(value)
		write(value)
		me.end()
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	encodes a value so that any special chars will be transformed into html entities.
	''					e.g. " will be &quot;
	'' @PARAM:			value [string]: the value you want to encode
	'******************************************************************************************************************
	public function HTMLEncode(value)
		HTMLEncode = server.HTMLEncode(value & "")
	end function
	
	'***********************************************************************************************************
	'' @SDESCRIPTION:	checks if a given string is a syntactically valid email
	'' @RETURN:			[bool] true if it is valid
	'***********************************************************************************************************
	public function isValidEmail(value)
		isValidEmail = false
		set regEx = new regExp
		
		regEx.pattern = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$" 
		regEx.ignoreCase = true
		retVal = regEx.test(value)
		
		if retVal then isValidEmail = true
		
		set regEx = nothing
		
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	returns null if the input is empty. 
	'' @PARAM:			value [variant]: the value you are dealing with
	'' @RETURN:			[variant] null if the value is empty, otherwise the value itself
	'******************************************************************************************************************
	public function nullIfEmpty(value)
		nullIfEmpty = value
		if trim(value & "") = "" then nullIfEmpty = null
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	removes all non-printable chars from the end and the beginning of the string
	'' @DESCRIPTION:	spaces, returns, line-feeds, tabs, etc. will be removed
	'' @PARAM:			inputStr [string]: string to be trimmed
	'' @RETURN:			[string] trimmed string
	'******************************************************************************************************************
	public function trimComplete(inputStr)
		stringLen = len(inputStr)
		
		if stringLen > 0 then
			'trim-left
			for i = 1 to stringLen
				if asc(mid(inputStr, i, 1)) > 32 then exit for
			next
			
			trimComplete = mid(inputStr, i)
			stringLen = len(trimComplete)
			
			'trim-right
			for i = stringLen to 1 Step - 1
				if asc(mid(trimComplete, i, 1)) > 32 then exit for
			next
			trimComplete = left(trimComplete, i)
		end if
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	removes all Tags from a given string
	'' @DESCRIPTION:	Tags are defined as string-parts surrounded by a < and a >. example: <sample>
	'' @PARAM:			inputStr [string]: string where the Tags should be removed
	'' @RETURN:			[string] the input-String without any Tags
	'******************************************************************************************************************
	public function stripTags(inputStr)
		set regEX = new RegExp
		regEX.pattern = "<[^>]*>"
		regEX.global = true
		stripTags = regEX.replace(inputStr & "", "")
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	divides a string into several string-paritions of a given length
	'' @DESCRIPTION:	string "HAXN" will result (partitionlength=2) in the following array:
	''					a(0) = "HA"; a(1) = "XN"
	'' @PARAM:			inputStr [string]: string which should be divided
	'' @PARAM:			partitionLength [string]: the length of each partion
	'' @RETURN:			[array] array with all partitions
	'******************************************************************************************************************
	public function divide(inputStr, byVal partitionLength)
		if partitionLength < 1 then exit function
		i = 0
		tmpArray = array()
		while (i * partitionLength) < len(inputStr)
			redim preserve tmpArray(i)
			tmpArray(i) = mid(inputStr, (i * partitionLength) + 1, partitionLength)
			i = i + 1
		wend
		divide = tmpArray
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	stops to response
	'******************************************************************************************************************
	public sub [end]()
		response.end
	end sub
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	shortens a string and adds a custom string at the end if string is longer than a given value.
	'' @PARAM:			str [string]: string which should be checked against cutting
	'' @PARAM:			maxChars [string]: whats the maximum allowed length of chars
	'' @PARAM:			overflowString [int]: what string should be added at the end of the string if it has been cutted
	'' @RETURN:			[string] cutted string
	'******************************************************************************************************************
	public function shorten(byVal str, maxChars, overflowString)
		str = str & ""
		if len(str) > maxChars then str = left(str, maxChars) & overflowString
		shorten = str
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	splits a string and returns a specified field of the array
	'' @DESCRIPTION:	it uses the split function but immediately returns you the field you want.
	'' @PARAM:			stringToSplit [string]: the string you want to split
	'' @PARAM:			delimiter [string]: whats the delimiter for splitting
	'' @PARAM:			returnIndex [int]: what index should be returned after spliting?. -1 = get the last index
	'' @RETURN:			[string] string content for the wanted field of the array
	'******************************************************************************************************************
	public function splitValue(stringToSplit, delimiter, returnIndex)
		tmpArray = split(stringToSplit, delimiter)
		if returnIndex = -1 then returnIndex = uBound(tmpArray)
		splitValue = tmpArray(returnIndex)
		tmpArray = null
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	adds a slash "/" at the end of the string if there isnt one.
	'' @DESCRIPTION:	Good use for urls or paths if you want to be sure that there is a slash at the end
	''					of an url or a path. 
	'' @PARAM:			pathString [string]: The string (url, path) you want to check
	'' @RETURN:			[string] the new url. with a slash at the end.
	'******************************************************************************************************************
	public function ensureSlash(pathString)
		ensureSlash = pathString
		if not me.endsWith(pathString, "/") then ensureSlash = pathString & "/"
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	writes a string to the output in the same line
	'' @PARAM:			value [string]: output string
	'******************************************************************************************************************
	public function write(value)
		response.write(value)
	end function
	
	'******************************************************************************************************************
	'' @SDESCRIPTION:	writes a line to the output
	'' @PARAM:			value [string]: output string
	'******************************************************************************************************************
	public function writeln(value)
		response.write(value & vbcrlf)
	end function
	
	'**************************************************************************************************************
	'' @SDESCRIPTION:	Converts a string to a "char" array
	'' @PARAM:			str [string]: the string you want to convert
	'' @RETURN:			[array] a "char" array
	'**************************************************************************************************************
	public function toCharArray(byVal str)
		redim charArray(len(str) - 1)
		for i = 0 to uBound(charArray)
			charArray(i) = mid(str, i + 1, 1)
		next
		toCharArray = charArray

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -