- Clojure - Libraries
- Clojure - Automated Testing
- Clojure - Applications
- Clojure - Concurrent Programming
- Clojure - Java Interface
- Clojure - Databases
- Clojure - Reference Values
- Clojure - Macros
- Clojure - Watchers
- Clojure - Agents
- Clojure - StructMaps
- Clojure - Metadata
- Clojure - Atoms
- Clojure - Date & Time
- Clojure - Destructuring
- Clojure - Predicates
- Clojure - Regular Expressions
- Clojure - Sequences
- Clojure - Exception Handling
- Clojure - Namespaces
- Clojure - Maps
- Clojure - Vectors
- Clojure - Sets
- Clojure - Lists
- Clojure - Strings
- Clojure - File I/O
- Clojure - Recursion
- Clojure - Numbers
- Clojure - Functions
- Clojure - Decision Making
- Clojure - Loops
- Clojure - Operators
- Clojure - Variables
- Clojure - Data Types
- Clojure - REPL
- Clojure - Basic Syntax
- Clojure - Environment
- Clojure - Overview
- Clojure - Home
Clojure Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Clojure - Strings
A String pteral is constructed in Clojure by enclosing the string text in quotations. Strings in Clojure need to be constructed using the double quotation marks such as “Hello World”.
Example
Following is an example of the usage of strings in Clojure.
(ns clojure.examples.hello (:gen-class)) (defn hello-world [] (println "Hello World") (println "This is a demo apppcation")) (hello-world)
Output
The above program produces the following output.
Hello World This is a demo apppcation
Basic String Operations
Clojure has a number of operations that can be performed on strings. Following are the operations.
Sr.No. | String Operations & Description |
---|---|
1 | The concatenation of strings can be done by the simple str function. |
2 | The formatting of strings can be done by the simple format function. The format function formats a string using java.lang.String.format. |
3 | Returns the number of characters in the string. |
4 | Returns the substring of ‘s’ beginning at start inclusive, and ending at end (defaults to length of string), exclusive. |
5 | Returns a negative number, zero, or a positive number when ‘x’ is logically less than , equal to , or greater than ‘y’. |
6 | Converts string to all lower-case. |
7 | Converts string to all upper-case. |
8 | Returns a string of all elements in collection, as returned by (seq collection), separated by an optional separator. |
9 | Sppts string on a regular expression. |
10 | Sppt strings is based on the escape characters or . |
11 | Reverses the characters in a string. |
12 | Replaces all instance of a match in a string with the replacement string. |
13 | Removes whitespace from both ends of the string. |
14 | Removes whitespace from the left hand side of the string. |
15 | Removes whitespace from the right hand side of the string. |