Working with Strings in Kotlin

The basic datatype of strings in kotlin is mostly similar as that of used in java. Only the declaration of the variable is different with Kotlin.

String declaration and definition in Kotlin

var myName:String = "lynxbee"

var VARIABLE_NAME:String = "ACTUAL_STRING"

Above is the simple declaration and definition of String in Kotlin.

Concatnating Strings with Kotlin

var myDomain:String = ".com"
myCompleteName = myName + myDomain

NEW_STRING = STRING1 + STRING2

Checking in Another string is present / Identify if substring exists in String

var myDomain:String = ".com"
var myCompleteName = "lynxbee.com"
if (myCompleteName.contains(myDomain)) {
    // this returns true, if domain .com is present in lynxbee.com string
}

Checking if a String starts with another substring

var myCompleteName = "https://lynxbee.com"
if (myCompleteName.startsWith("http")) {
    // this returns true, if domain lynxbee.com is started with http or https
}
Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense Multimedia - Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question