假设,我有一个数组:
int[] arr = new int[] {1, 2, 3, 4, 5, 6, 7};
Run Code Online (Sandbox Code Playgroud)
我需要使用分隔符连接其元素,例如," - "因此我应该得到这样的字符串:
"1 - 2 - 3 - 4 - 5 - 6 - 7"
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
假设,我有一个字符串:
String str = "some strange string with searched symbol";
Run Code Online (Sandbox Code Playgroud)
我想在其中搜索一些符号,假设它会是"string".所以我们有以下内容:
str.matches("string"); //false
str.matches(".*string.*"); //true
Run Code Online (Sandbox Code Playgroud)
那么,正如标题中所述,为什么我必须在Java正则表达式中指定整个字符串?
Java文档说:
public boolean matches(String regex)
判断此字符串是否与给定的正则表达式匹配.
它没有说
判断整个字符串是否与给定的正则表达式匹配.
例如,php它将是:
$str = "some strange string with searched symbol";
var_dump(preg_match('/string/', $str)); // int(1)
var_dump(preg_match('/.*string.*/', $str)); //int(1)
Run Code Online (Sandbox Code Playgroud)
所以,两个正则表达式都将是true.
我认为这是正确的,因为如果我想测试整个字符串,我会这样做str.matches("^string$");
PS:是的,我知道这是搜索子字符串,更简单,更快将使用str.indexOf("string")或str.contains("string").我的问题只涉及Java正则表达式.
更新:如@ ChrisJester-Young(和@GyroGearless)所述,其中一个解决方案,如果你想搜索regex主题字符串的一部分,就是使用这样的find()方法:
String str = "some strange string with searched symbol";
Matcher m = Pattern.compile("string").matcher(str); …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到python 3.7,我意识到我所有的模块都停留在以前的版本中。甚至Django也不再被认可。如何将所有内容转移到新版本?我现在有点迷茫,甚至不知道新版本的安装位置。
编辑:
当我执行$ which python3.6此操作时,终端会告诉我它不存在,但是我在中有一个python3.6目录/usr/local/lib/,其中安装了所有模块。
在同一目录中,/usr/local/lib/我还有一个python3.7目录,其中安装了一些模块,但缺少许多模块。但是,当我python3.7在查找器中搜索文件时,它不会出现。当我这样做时$ which python3.7,路径/usr/local/bin与目录不一样。
任何人都可以看到发生了什么,知道如何将所有模块转移到python3.7吗?
我想通过浏览按钮控件上传Excel文件.我不需要保存它.然后,在单击按钮时,如何在Excel中读取数据并在网格视图中显示它.我需要使用MVC来完成这个任务.
请帮忙.
谢谢,Nayan
我刚刚从 symfony 4.1 迁移到 4.4 我有这个错误:
传递给 App\EventListener\KernelRequestListener::__construct() 的参数 1 必须是 Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage 的实例,Symfony\Component\Security\Core\Authentication\Token\Storage 的实例\UsageTrackingTokenStorage 给定,在 C:\xampp\htdocs\chat-project-symfony\var\cache\dev\Container06Mjwya\srcApp_KernelDevDebugContainer.php 中调用,第 1130 行
而如果你看看我的KernelRequestListener:
<?php
namespace App\EventListener;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
//..
class KernelRequestListener
{
private $tokenStorage;
/**
* KernelRequestListener constructor.
* @param TokenStorage $tokenStorage
* ...
*/
public function __construct(TokenStorage $tokenStorage/*...*/)
{
$this->tokenStorage = $tokenStorage;
//..
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的config/services.yaml文件:
#...
services:
#..
App\EventListener\KernelRequestListener:
arguments: [ '@security.token_storage' ]
tags:
- { name: kernel.event_listener, event: kernel.request }
- { name: kernel.event_listener, event: kernel.response …Run Code Online (Sandbox Code Playgroud)