我想删除字符串中的额外空格。我试过trim,ltrim,rtrim和其他人,但是他们中没有人在工作,甚至尝试了下面的东西。
//This removes all the spaces even the space between the words
// which i want to be kept
$new_string = preg_replace('/\s/u', '', $old_string);
有什么解决办法吗?
更新:-
输入字符串:-
"
Hello Welcome
to I
虽然将列表作为用户的输入,但应该将输入括在方括号中,而不只是键入数字这是我的代码,用于从用户获取列表的多个输入
a = list(map(int,input().strip().split(', ')))
默认输入是1,2,3,4。当我运行代码时,我得到一个错误,如下所示:
ValueError: invalid literal for int() with base 10: '[1'
我知道发生这种情况的原因是因为'[1‘是一个无法转换为int的元素,并且它(方括号和1)被视为索引为0的列表中的第一个元素。拥有方括号对我来说是绝对必要的,我如何解决错误
当自动格式化在TypeScript/JavaScript中的模板文字中插入的SQL代码时,WebStorm会自动添加前导空格以将每一行与声明行对齐,即
const query = `
select field1 as x,
field123456789 as y,
from mytable
`;
而不是首选
const query = `
select field1 as x,
field123456789 as y,
from
用户在System.in中键入此 1 2 3 4 44 50 and so on 我需要从中获取int数组,所以我的解决方案是: import java.util.Scanner;
public class Program
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String tempString = in.nextLine();
int tempArray[] = tempString.split("
所以基本上我有像这样的输入阅读器:
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String userInput = stdIn.readLine();
if (userInput != null) {
String message = username + ":" + userInput;
}
}
当我在终端中输入一些文本时,让我们这样说:
this is a test
然后我按回车键,它就会停在那
我有一个包含其他元素(a,span)的html元素,这些元素包含像"this is a text“这样的文本。因为一些单词在a和/或span中,所以text()的结果类似于" this\n is a\n text "。我对所有的空格都不感兴趣。我只想测试"this is a text“是否是元素中的可读文本。
我可以通过使用正则表达式来解决这个问题,例如assert.ok(string.match(/^\s*this\s+is\s+a\s+text\s*^/)),但是这有点难看,而且我会丢失"expec
我有一个数据框,如下所示:
Col1
123/ House Number 5
345/ House Number 10
678/ House Number 15
我想删除字符串之前的数值,而不是字符串之后的值(您可以假设它们的格式都是数字后跟破折号的示例中所示的格式)。
我使用了以下代码,但它删除了所有数字字符,而不考虑位置:
df['Col1'] = df['Col1'].str.replace('\d+', '')
有没有办法只删除字符串前的数字?
有没有办法改变自动生成的代码在eclipse中的样子?
目前,它会生成如下代码
int a = something;
但我真的希望它能像这样
int a=something
也就是说:没有所有额外的空间。这也适用于函数,在函数前有一个额外的空格,
我真的更喜欢f(int a,int b);而不是f(int a,int b);