嘿,我一直在尝试编写一个简单的 javascript 函数来比较字符串字母,但由于某种原因我无法使其工作......这是代码。
function compare(wordOne, wordTwo) {
if (wordOne.substring(0) === wordTwo.substring(0))
{
return true;
} else {
return false;
}
}
compare("house", "hell");
Run Code Online (Sandbox Code Playgroud) 我需要从字符串末尾删除所有特殊字符,这些字符有时会出现,有时不会。
我已经写了这个.gsub(/[,()'"]./,''),但它并没有.从字符串中删除(句号)。
你能告诉我这有什么问题吗?
我们的 MS Flow - 更新项目任务中有这个公式...
concat(items('Apply_to_each')['T_x002d_Code']
,'-'
,items('Apply_to_each')['BoxNo']
,'-'
,
items('Apply_to_each')['ID'])
Run Code Online (Sandbox Code Playgroud)
但我们需要在 BoxNo 和 ID 中添加前导零,因此最终结果如下:
A02-00001-000235
我们也尝试过:
substring(concat('000000', variables('ItemID'))
, sub(5, length(variables('BoxNo')))
, add(6, length(variables('ItemID'))))
Run Code Online (Sandbox Code Playgroud)
但没有运气。
BoxNo值可以从 1到99,999,因此我们需要填充最多4 个前导零
ItemID可以从 1 到 999,999 ,因此我们需要填充最多5 个前导零
我们如何才能像这样格式化这些字段呢?
我知道这可能看起来很愚蠢,但我一直在到处寻找并尝试使用正则表达式并徒劳地分割。我的脚本永远不适用于我的数据集上的所有类型的字符串。
\n\n我的这一列包含原始数据,如下所示(三种情况):
\n\n20181223-FB-BOOST-AAAA-CC Auchy-Les-Mines - P\xc3\xa8re Noel\n20161224-FB-BOOST-SSSS-CC LeMarine - XXX XXX\n20161223-FB-BOOST-XXXX-CC Bonjour le monde - Blah blah\nRun Code Online (Sandbox Code Playgroud)\n\n所以我想做的是将字符串放在 CC 之后和“-”之前的中间。我编写了一个脚本,适用于第二种情况,但不适用于其他两种情况:
\n\n1st case: Auchy-Les-Mines\n2nd case: LeMarine\n3rd case: Bonjour le monde\nRun Code Online (Sandbox Code Playgroud)\n\n这是我使用的正则表达式,但不适用于所有情况: regex =r"\\s\\b.*-."
提前致谢 !
\n我正在尝试为 pyspark 数据框中的每一行删除一列中的前两个字符。以下字符的长度不同,因此我无法使用substring的解决方案。
示例数据框:
columns = ['text']
vals = [(h0123),(b012345), (xx567)]
Run Code Online (Sandbox Code Playgroud)
编辑 实际上问题变得更加复杂,因为有时我有一个字母和两个零作为第一个字符,然后需要删除两个 0。
例子:
columns = ['text']
vals = [(h0123),(b012345), (x00567), (L0034)]
Run Code Online (Sandbox Code Playgroud)
预期结果:
(123),(12345), (567), (34)
Run Code Online (Sandbox Code Playgroud) 我有一个,我想获取字符串中最后一个点string之后的单词。 .
例子:
string input = "XimEngine.DynamicGui.PickKind.DropDown";
Run Code Online (Sandbox Code Playgroud)
结果:
DropDown
Run Code Online (Sandbox Code Playgroud) 尽管进行了大量研究,我还是找不到解决方案。我被 contains 函数困住了。我有这个 Json 文件:
{
"from": "Api",
"success": true,
"message": "",
"errors": [],
"data": {
"operations": [
{
"IDOperation": 100,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh5 numero 152",
"sous_operations": []
},
{
"IDOperation": 101,
"DateEcriture": "2019-01-02",
"Comment": "one other thing",
"sous_operations": []
},
{
"IDOperation":102,
"DateEcriture": "2019-01-02",
"Comment": "an other thing",
"sous_operations": [{"ID-sous-Operation": 103,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh15 numero 341"}]
}]
}
}
Run Code Online (Sandbox Code Playgroud)
我想过滤“注释”字段中包含“发票”一词的对象以获得以下结果:
{"operations": [
{
"IDOperation": 100,
"DateEcriture": "2019-01-02",
"Comment": "Invoice Nh5 numero 152"
},
{
"IDOperation": …Run Code Online (Sandbox Code Playgroud) 我有一个新闻标题列表,想检查是否有标题包含列表中的任何关键字。
例如
newstitle =['Python is awesome', 'apple is tasty', 'Tom cruise has new movie']
tag = ['Python','Orange', 'android']
Run Code Online (Sandbox Code Playgroud)
tag如果in 中有任何关键字newstitle,我希望它返回True。
我知道如何使用单个标签来做到这一点:
any('Python' in x for x in newstitle)
Run Code Online (Sandbox Code Playgroud)
但是如何使用多个关键字呢?
在 Kotlin 中,我需要从字符串中删除第一个和最后一个字符。这似乎出现编译错误:
val MyPiece = str.substring(0, str.length - 1)
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
许多迭代器方法都是 Rust 生成的迭代器包裹在迭代器中的。一种这样的情况是方法skip,它跳过给定数量的元素并生成包装在Skip实现该Iterator特征的结构中的剩余元素。
我想逐行读取文件,有时会跳过n一行的第一个字符。我认为 usingIterator.skip会起作用,但现在我一直在思考如何实际解开生成的Chars迭代器,以便我可以使用 来实现剩余的&str内容chars.as_str()。
在 Rust 中展开迭代器的惯用方法是什么?调用链
let line: &String = ...;
let remaining = line.chars().skip(n).as_str().trim();
Run Code Online (Sandbox Code Playgroud)
引发错误
error[E0599]: no method named `as_str` found for struct `std::iter::Skip<std::str::Chars<'_>>` in the current scope
--> src/parser/directive_parsers.rs:367:63
|
367 | let option_val = line.chars().skip(option_val_indent).as_str().trim();
| ^^^^^^ method not found in `std::iter::Skip<std::str::Chars<'_>>`
error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)