我试图根据文件的最长公共前缀 cpfx 来匹配文件,并且对 haskell 有点陌生。我正在尝试获取列表列表并简单地返回它们共享的前缀。例如:
cpfx ["obscure","obscures","obscured","obscuring"] --> "obscur"
cpfx ["abc", "ab", "abcd"] --> "ab"
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用几个辅助方法,如下所示:
cpfx :: [[Char]] -> [Char]
cpfx [] = [] -- nothing, duh
cpfx (x:[]) = x -- only one thing to test, return it
cpfx (x:t) = cpfx' (x:t) 0 -- otherwise, need to test
cpfx' (x:[]) _ = []
cpfx' (x:t) n
-- call ifMatch to see if every list matches at that location, then check the next one
| ifMatch (x:t) n …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序来检查第一个列表是否是第二个列表的前缀。例如,[5,6] 是 [1,5,6,7] 的前缀。这是我的工作代码,但基本上我不知道如何去做。
prefix [Int] -> [Int] -> Bool
prefix [] [] = []
prefix y (x:xs)
| x == y = prefix y xs
| otherwise = 0
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
在一个.owl文件中,我声明了一些前缀,如下所示:
Prefix(:=<http://default.ont/my_ont/>)
Prefix(ex:=<http://example.org/ex#>)
Prefix(ex2:=<http://example2.org/ex#>)
...
Run Code Online (Sandbox Code Playgroud)
在 Java 项目中使用我的本体,如下所示:
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(resourceFullPath(ontologyFilename)));
Run Code Online (Sandbox Code Playgroud)
现在我想Map<String, String>以编程方式构建一个包含以下内容的程序:
{
"" -> "http://default.ont/my_ont/",
"ex" -> "http://example.org/ex#",
"ex2" -> "http://example2.org/ex#"
}
Run Code Online (Sandbox Code Playgroud)
我如何使用OWL API执行此操作(即无需.owl自己解析文件)?
我有以下多个交易传递给交易string:
string transaction = "12345,56789";
Run Code Online (Sandbox Code Playgroud)
我想检查该交易是否具有前缀“0”,那么如何检查。
例如
"012345,056789";
Run Code Online (Sandbox Code Playgroud)
假设这些交易没有像"12345,56789"这样的前缀 '0'我想添加像这样的前缀"012345,056789"。
我尝试使用下面的代码它对我不起作用,任何人都可以指导我如何实现这一目标。
if(transaction.StartsWith("0"))
{
transaction = transaction;
}
else
{
transaction = "0" + transaction;
}
Run Code Online (Sandbox Code Playgroud) 在我使用前缀之前,我可以正常使用暗模式,但是在我的顺风类中添加前缀后,我不能再使用暗模式了,有人知道如何使用前缀切换暗模式吗?
我有一个前缀表达式,它只有 4 个二元运算符 (+,-,*,/) 。评估此类表达式的直接方法是将其转换为后缀表达式,然后评估该表达式。但是我正在寻找一种直接执行此操作而不将其转换为任何其他表达式的算法?
language-agnostic algorithm infix-notation prefix postfix-notation
我想删除所有具有通用前缀名称的文件夹/目录。这如何在 python 中实现?
示例:名称带有前缀的所有文件夹 - 'reports_'
我正在执行以下命令来获取必须从其上方的行添加前缀的行,如下所示:
grep -B1 "^E[0-9]"
Run Code Online (Sandbox Code Playgroud)
我得到的东西如下:
ENSG00000165661:E5.1
E6.1
--
ENSG00000174776:E7.1
E8.1
--
ENSG00000122482:E7.2
E8.1
Run Code Online (Sandbox Code Playgroud)
如何为以E [字母数字]开头的行添加前缀,使文件成为
ENSG00000165661:E5.1
ENSG00000165661:E6.1
ENSG00000174776:E7.1
ENSG00000174776:E8.1
ENSG00000122482:E7.2
ENSG00000122482:E8.1
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个String将前缀字符串添加到现有字符串中的函数.
问题我是:有时候,我从没有关键字http的 Web服务响应中获取url字符串.
URL的一般形式(url字符串)应为:http://www.testhost.com/pathToImage/testimage.png
但有时我会//www.testhost.com/pathToImage/testimage.png从网络服务中获得.
现在,我知道我可以检查http:字符串中是否有前缀,但如果没有,那么我需要在现有的url字符串中添加前缀.
是否有任何String(或子字符串或字符串操作)函数在我的url字符串中添加前缀?
我试过Apple文档:String但找不到任何帮助.
我有另一种方法是连接字符串.
这是我的代码:
var imageURLString = "//www.testhost.com/pathToImage/testimage.png"
if !imageURLString.hasPrefix("http:") {
imageURLString = "http:\(imageURLString)" // or "http:"+ imageURLString
}
print(imageURLString)
Run Code Online (Sandbox Code Playgroud)
但是我可以在这里使用任何标准方式或iOS String默认功能吗?
我有一个整数字段(银行帐号).在将它保存在轨道中时,如果它包含任何前面的零点,那么零点会被轨道自动修剪(移除),如下所示.
.gems :086 > bank_detail = BankDetail.new
=> #<BankDetail id: nil, account_name: nil, account_no: nil, bank_name: nil, branch_name: nil, ifsc_code: nil, user_id: nil, created_at: nil, updated_at: nil>
.gems :087 > bank_detail.account_no = "0123456"
=> "0123456"
.gems :089 > bank_detail.save(:validate => false)
(0.2ms) BEGIN
SQL (0.5ms) INSERT INTO "bank_details" ("account_no", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["account_no", 123456], ["created_at", "2018-07-17 15:47:35.062139"], ["updated_at", "2018-07-17 15:47:35.062139"]]
(22.7ms) COMMIT
=> true
.gems :090 >
.gems :090 > BankDetail.last
BankDetail Load (0.6ms) SELECT …Run Code Online (Sandbox Code Playgroud)