generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: String manipulation

Previous Thread :: Next Thread 
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 11:15 AM
local function findWord(s,tab)
for i,v in pairs(tab)do
print('Looking for: '..v)
local S,E = string.find(s:lower(),v:lower())
if S and E and (S==1 or string.sub(s:lower(),S-1,S-1):match('[%p%s]'))and(E==s:len() or string.sub(s:lower(),E+1,E+1):match('[%p%s]'))then
return S,E
else
print(v.." wasn't found")
end
end
return nil,nil
end

's' is a string. tab is a table of strings.

In one instance, 's' is 'come me' and tab is {"me","meh"}

In the conditional statement, I first determine if S and E are a thing.

Next, I determine if S is 1 (which means it is the first word) or if the character before S is a punctuation character or a white-space character ('[%p%s]')

Next, I determine if E is equal to s:len() (which means it is the last word) or if the character after E is a punctuation character or a white-space character ('[%p%s]')

But for some reason, it always returns nil.

Basically, I just want to determine if one of the strings in tab is a single word.

Example:

I want to find 'me'.
I do not want to find the two characters 'm' and 'e' as in the word 'come' but I do want to find them if it is in the form of: 'come me'

This is used as an example of 'come to me'


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 11:42 AM
bump


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
HlCOM is not online. HlCOM
Joined: 29 Mar 2009
Total Posts: 3332
10 Dec 2016 11:52 AM
might be dropping the ball here but w/e


local strings = {'come to me', 'hellocometome','hello come to me','come'}


for i,v in ipairs (strings) do
if v:match(' me ') or v:match(' me') and not v:match(' me%.') then
print('true',v)
else
print('false',v)
end
end



what about something like that?
Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 12:28 PM
mine is probably not good but this is what i do.
it just puts every word that is sep'd by a space into a table. then compare each word with each value of the other table.

local function findWord(s,t)
local words,finds={},{}
for k in s:gmatch("([%w%p]+)%s?") do
words[#words+1]=k:lower()
end
for k,v in next,t do
for i=1,#words do
if words[i]==v:lower() then
finds[#finds+1]=v
end
end
end
return finds
end

print(table.concat(findWord("come me",{"me","meh"}),",")) --> me



Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 02:11 PM
Sorry, not working in the way I need it to.

Does anyone know what is wrong with my function?


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 02:16 PM
Mine worked for me?


Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 02:17 PM
I'll probably have to change it some.

What I'm doing is returning the positions of the word.

Example:

local word = 'guy'

local string = 'Hello guy man'

> 7 9


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
10 Dec 2016 02:20 PM
why is this so complicated

local words = {'me'}

CheckVal = function(tab,val)
for i,v in next, tab do
if v == val then
return true
end
end
end

GetWord = function(s,word)
for m in s:gmatch('%a+') do
if CheckVal(words,m) then
return m
end
end
end

local word = 'me'

local s = 'come me mee'
print(GetWord(s,word)) >> me

s = 'come mee'
print(GetWord(s,word)) >> nil


Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 02:34 PM
Thanks for the response @TimeTicks.

But I need the position of the word.

findWord('come me',{'me,meh'})

>>6 7


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 04:24 PM
######################################################################################################################################################################################################################################################################################################################################################################################################################
Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 04:25 PM
was confused the first time.

goo.gl/YvBxKR


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
10 Dec 2016 04:29 PM
string.find(string,word)

duh


Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 04:33 PM
goo.gl/0WoqyY

if you don't want error on the first one ;) cause I used [i-1] so sometimes it will be nil


Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 04:37 PM
#############################################################################################################################################################################################################################################################################################################################
Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 04:37 PM
i cant even write regular words without tags


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
10 Dec 2016 04:48 PM
please click preview before posting


Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 07:59 PM
I'm on mobile right now, so I haven't tried any links or code, but @TimeTicks, if I use string.find() wouldn't I be right back where I started? To where it'll just find the "me" in the word "come"
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 09:14 PM
As always, I feel stupid. Since string.find() will search for the FIRST pattern of the string, it will stop searching after that. I fixed it by having a for loop. ## ### for i=1,s:len() local S,E = string.find(string,pattern,i) do The third argument is where to specify the searching point Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
10 Dec 2016 09:15 PM
As always, I feel stupid.

Since string.find() will search for the FIRST pattern of the string, it will stop searching after that.

I fixed it by having a for loop.

As stated below: -- I literally had this line as 'as' and 'so:'

for i=1,s:len()
local S,E = string.find(string,pattern,i)
do

The third argument is where to specify the searching point


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
newcoolman2 is not online. newcoolman2
Joined: 01 Apr 2010
Total Posts: 2637
10 Dec 2016 09:33 PM
yeah in mine on the seconds link I used the third argument.
I have a table of the words and I make it start from the word before :)


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image