Forum

> > CS2D > Scripts > Another String Request
Forums overviewCS2D overview Scripts overviewLog in to reply

English Another String Request

3 replies
To the start Previous 1 Next To the start

old Another String Request

Infinite Rain
Reviewer Off Offline

Quote
Guys how can i return certain letter from string?
Example:
1
2
3
function return_certain_latter(stringg, latter)
	return string.latter(stringg, latter)
end

return_certain_letter('Hello world!", 7)
it'll return "W"

old Re: Another String Request

KimKat
GAME BANNED Off Offline

Quote
Take a look at this page and it'll give you a idea of how to return a character from a string.

Basically it works like this...
1
2
String lineOfText = "Hello there."; 
char aChar = lineOfText.charAt(6);
The code above will take out the letter "t" from the string.

To take out a whole string you need to do it like this...
1
2
String lineOfText = "Hello there."; 
String there = anotherPalindrome.substring(6, 11);
This will take out the text "there" from the string.

old Re: Another String Request

IWhoopedPythagoras
BANNED Off Offline

Quote
user KimKat has written
Take a look at this page and it'll give you a idea of how to return a character from a string.

Basically it works like this...
1
2
String lineOfText = "Hello there."; 
char aChar = lineOfText.charAt(6);
The code above will take out the letter "t" from the string.

To take out a whole string you need to do it like this...
1
2
String lineOfText = "Hello there."; 
String there = anotherPalindrome.substring(6, 11);
This will take out the text "there" from the string.


Lua is weakly typed... You don't have to specify wether its a string number boolean or table ( chars don't exist in lua) I think you kinda mixed up because you gave Java code not lua. While the syntax that Factis699 provides is lua syntax.


1
2
3
function return_certain_latter(stringg, latter)
	return stringg:sub(latter,latter)
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview