You can split a String on a particular delimiting character or a Regular Expression, you can use the () method that has the following signature:
E'tibor bering, chegaralovchi belgi yoki muntazam ifoda hosil bo'lgan string massividan o'chiriladi.
Chegaruvchi belgidan foydalanishga misol:
String lineFromCsvFile = "Mickey;Bolton;12345;121216";
String[] dataCells = lineFromCsvFile.split(";");
// Result is dataCells = { "Mickey", "Bolton", "12345", "121216"}; Example using regular expression:
String lineFromInput = "What do you need from me?";
String[] words = lineFromInput.split("\\s+"); // one or more space chars
// Result is words = {"What", "do", "you", "need", "from", "me?"}; You can even directly split a String literal:
String[] firstNames = "Mickey, Frank, Alicia, Tom".split(", ");
// Result is firstNames = {"Mickey", "Frank", "Alicia", "Tom"};
Warning: Do not forget that the parameter is always treated as a regular expression.
Oldingi misolda. har qanday belgiga mos keladigan muntazam ifoda joker belgisi sifatida ko'rib chiqiladi va har bir belgi chegaralovchi bo'lgani uchun natija bo'sh massiv bo'ladi.
Quyidagi belgilar regexda maxsus (aka meta-belgilar) hisoblanadi
Yuqoridagi chegaralovchilardan biriga asoslanib satrni ajratish uchun ularni \\ orqali olib tashlashingiz yoki foydalanishingiz kerak.
Do'stlaringiz bilan baham: |