Questions about finding a specific string in a string

Asked 2 years ago, Updated 2 years ago, 50 views

varMessage =   
            "hi/thsid/sdfhsjdf/dfjsd/sdjfsdn\n"


            "/my/name/is/balaji.so\n"
            "call::myFunction(int const&)\n"
            "void::secondFunction(char const&)\n"
             .
             .
             .
            "this/is/last/line/liobrary.so"

How do I create a method that finds out if a string like "hi" or "this/is" is included when I have this string?

ruby string

2022-09-22 21:59

1 Answers

#include? method.

Returns true if str contains the given string or character.

If str contains other_str, return true

my_string = "abcdefg"
if my_string.include? "cde"
   puts "String includes 'cde'"
end


2022-09-22 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.