首页 > 解决方案 > Swift - 基于阿拉伯语组合字符拆分文本

问题描述

亲爱的,

我有这样的阿拉伯语句子

أكل الولد التفاحة

如何根据 UNCONNECTED 字符拆分句子,如下所示:

أ - كل

ا - لو - لد

ا - لتفا - حة

我把-解释我的意思。我只需要根据它将文本拆分为数组

我如何使用ios 的swift代码来做到这一点?

更新:我不在乎空间。例如,“أكل”是一个单词,不包含空格。我想根据 UNCONNECTED 字符进行拆分。所以“أكل”由两个对象组成:“أ”和“كل”

الولد : 三个对象 "ا" 和 "لو" 和 "لد"

标签: iosarraysswiftsplitarabic

解决方案


有两个框,您可以先单击。内容自动粘贴点击转换。输出数据自动复制我用于此古兰经的空格

<h1>Allah</h1>
<center>
<textarea id="field" onclick="paste(this)" style="font-size: xxx-large;min-width: 90%;     min-height: 200px;"> </textarea>
<center>
</center>
</br>
<textarea id="field2" style="font-size: xxx-large;min-width: 95%;     min-height: 200px;"> </textarea>
</center>
<center>
<br>

<button onclick="myFunction()"  style="font-size: xx-large;min-width: 20%;">Convert</button>
</center>

<script >

function myFunction(){
var string = document.getElementById("field").value;

// Option 1
string.split('');

// Option 2
console.log(string);

// Option 3
Array.from(string);

// Option 4
var bb = Object.assign([], string);
console.log(bb);

    cleanArray = bb.filter(function () { return true });
    
      var filtered = bb.filter(function (el) { 
                return el != null; });

console.log(filtered);
var bb = bb.toString();

console.log(bb);
bb  = bb.replace(",","");

var stringWithoutCommas = bb.replace(/,/g, ' ');

console.log(stringWithoutCommas);

document.execCommand(stringWithoutCommas)
document.getElementById("field2").value = stringWithoutCommas;

  var copyTextarea = document.querySelector('#field2');
  copyTextarea.focus();
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
};

/*
var copyTextareaBtn = document.querySelector('#newr');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('#field2');
  copyTextarea.focus();
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});
*/
async function paste(input) {
document.getElementById("field2").value = "";
  const text = await navigator.clipboard.readText();
  input.value = text;
}

</script>

推荐阅读