Last active
January 22, 2019 10:01
-
-
Save abdurrahmanekr/8a31c73387957a9e5110bb4254332f69 to your computer and use it in GitHub Desktop.
ToCapitalizeCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//******************************************************************* | |
// Welcome to CompileJava! | |
// If you experience any issues, please contact us ('More Info') --> | |
// Also, sorry that the "Paste" feature no longer works! GitHub broke | |
// this (so we'll switch to a new provider): https://blog.github.com\ | |
// /2018-02-18-deprecation-notice-removing-anonymous-gist-creation/ | |
//******************************************************************* | |
import java.lang.Math; // headers MUST be above the first class | |
import java.util.Locale; | |
// one class needs to have a main() method | |
public class HelloWorld | |
{ | |
// arguments are passed using the text field below this editor | |
public static void main(String[] args) | |
{ | |
Test myObject = new Test(); | |
String str = myObject.toCapitalizeCase("KÜRŞAT ŞIMŞET IZGARA KÖFTE ŞİŞKEBAB"); | |
System.out.print(str); | |
} | |
} | |
// you can add other public classes to this editor in any order | |
class Test { | |
public String toCapitalizeCase(String str) { | |
Locale tr = Locale.forLanguageTag("tr-TR"); | |
if (str == null) | |
return ""; | |
str = str.toLowerCase(tr); | |
String[] spaces = str.split(" "); | |
for (int i = 0; i < spaces.length; i++) | |
{ | |
String firstChar = Character.toString(spaces[i].charAt(0)).toUpperCase(tr); | |
spaces[i] = firstChar + spaces[i].toString().substring(1, spaces[i].length()); | |
} | |
str = String.join(" ", spaces); | |
return str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment