ios - Swift - 基于阿拉伯语组合字符拆分文本
问题描述
亲爱的,
我有这样的阿拉伯语句子
أكل الولد التفاحة
如何根据 UNCONNECTED 字符拆分句子,如下所示:
أ - كل
ا - لو - لد
ا - لتفا - حة
我把-解释我的意思。我只需要根据它将文本拆分为数组
我如何使用ios 的swift代码来做到这一点?
更新:我不在乎空间。例如,“أكل”是一个单词,不包含空格。我想根据 UNCONNECTED 字符进行拆分。所以“أكل”由两个对象组成:“أ”和“كل”
الولد : 三个对象 "ا" 和 "لو" 和 "لد"
解决方案
有两个框,您可以先单击。内容自动粘贴点击转换。输出数据自动复制我用于此古兰经的空格
<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>
推荐阅读
- android - 如何在 Angular NativeScript Android 应用程序中自定义带有动画的主启动画面?
- google-analytics - GA 通过单击 GA 事件跟踪的按钮来触发新会话
- ctypes - 从 .whl 文件成功安装 Windows 10 Rtree,但运行代码时出错
- laravel - 试图从另一个表中获取引用的 Laravel Eloquent 数据
- spyder - 将 Spyder 更新到 4.0 后出现错误 qtconsole
- r - 如何在 R 中重构数据框(行到列)
- unreal-engine4 - 蓝图每次编译都会重置变量值
- java - Java 正则表达式导致空指针异常错误
- python - 如何在 Pandas DataFrame 中使用数学 Log 函数
- azure - 在 Azure Dev Ops 中的版本之间共享信息