Example:
<%
@number = "1,2,3,4,5,6"
@split = @number.split(",")
str = Array.new
count = 0
for i in 0...@split.length
if ( @split[i].to_i != 4 )
str[count] = @split[i]
count += 1
else
end
end
result = str*","
%>
<%= result %>
@number = "1,2,3,4,5,6"
@split = @number.split(",")
str = Array.new
count = 0
for i in 0...@split.length
if ( @split[i].to_i != 4 )
str[count] = @split[i]
count += 1
else
end
end
result = str*","
%>
<%= result %>
Output:
1,2,3,5,6
Class Library : http://corelib.rubyonrails.org/classes/Array.html
Instead of this, we can use another method as follows :
ReplyDeleteresult =[]
result = @number.delete("4,")
Shorter steps! Awesome! Thanks for sharing.
Delete