 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
the underminer
Joined: 03 Oct 2005 Posts: 124 Location: Netherlands
|
Posted: Fri Mar 30, 2007 4:43 am Post subject: finding | in string |
|
|
Hey All,
I want to make a function that searches for | (pipe symbol) and returns each string between the mathes. I'm not very good with string.find or string.gmatch. I read the documentation but I still don't understand. What I want is:
| Code: |
str = "hello there,|How are you all?|Nice day isn't it?"
result:
hello there,
How are you all?
Nice day isn't it?
|
hope you understand. I want to use | as a divider for lines.[/code] _________________ Behold! The Underminer got hold of a PSP |
|
| Back to top |
|
 |
Altair
Joined: 20 May 2006 Posts: 76 Location: The Netherlands
|
Posted: Sat Mar 31, 2007 9:57 pm Post subject: |
|
|
I know this function that was made by LuMo.
| Code: | function explode(text_ex, needle)
local array={}
_, count = string.gsub(text_ex, needle, needle)
for index=1,count+1 do
i, j = string.find(text_ex, needle)
if i == nil or j==nil then
i=0
j=0
end
table.insert(array,string.sub(text_ex, 1, i-1))
text_ex=string.sub(text_ex, j+1 )
end
return array
end |
Where:
text_ex is the string
needle is the divider
So in your case you would do:
| Code: | | newarray = explode(str, "|") |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|