Forum

> > CS2D > Scripts > Find any letter in string
Forums overviewCS2D overview Scripts overviewLog in to reply

English Find any letter in string

4 replies
To the start Previous 1 Next To the start

old Find any letter in string

Deleted User

Quote
Guys how to return true if function find letter in a string?
retrn('43244346g435') will return true
retrn('235345536') will return false

PLZ help me!

Thanks guys
edited 1×, last 06.09.11 06:00:17 am

old Re: Find any letter in string

Bowlinghead
User Off Offline

Quote
You can use string.gfind
And if you want to find letters you have to use "%a".

Here is an example:
1
2
3
4
5
-- WARNING: Untested
function my_func()
	mystring = "123456789"
	my_func = string.gfind(mystring,"%a")
end

old Re: Find any letter in string

DC
Admin Off Offline

Quote
you probably can also do this with a type conversion (untested):
1
2
3
4
5
6
7
function hasletter(mystring)
	if tostring(tonumber(mystring))==tostring(mystring) then
		return false
	else
		return true
	end
end

idea: tonumber will discard all letters and only keep numbers. so if the string is a pure number then the function will return false, if it's not a number but also contains different characters then it will return true.

depends on how you want to use it because it does not only detect letters but also other characters.

(this would actually be better to check if a string is a number or not)

old Re: Find any letter in string

Apache uwu
User Off Offline

Quote
Or a type check...

1
2
3
4
5
6
7
8
9
10
11
12
function isnumber(str)
	if type(tonumber(str))=="number"
		return true
	else
		return false
	end
end

isnumber("2093845") --> true
isnumber("236589f2683794") --> false
isnumber("") --> false
isnumber("-10") --> true
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview