Vala examples III

Working with strings. Can i concat strings ? Can i compare two strings ? Sureeeee 🙂


/* string1.vala                       */
/* valac -o string1 string1.vala */
using GLib;

public class Sample : Object {
        public Sample () {
        }

        public void concat_example () {
                string s1 = "hello, " ;
                string s2 = "my name is telemaco" ;

                stdout.printf("contat: %s\n", s1.concat(s2)) ;
        }

        public void are_equal (string str1, string str2) {
                stdout.printf("are_equal: ");
                if (str1 == str2) {
                        stdout.printf("%s == %s\n", str1, str2);
                }
                else
                {
                        stdout.printf("%s != %s\n", str1, str2);
                }
        }

        static int main (string[] args) {
                var sample = new Sample ();
                sample.concat_example ();
                sample.are_equal("apple", "orange");
                sample.are_equal("apple", "apple");
                return 0;
        }
}

Leave a Reply

Your email address will not be published. Required fields are marked *