为什么这不起作用?
$content=file_get_contents('whatever.txt');
$content=str_replace("\r\n","\n",$content); // Convert linebreaks
$content=str_replace("\n",' ',$content); // Remove linebreaks
$content=preg_replace('/\s+/',' ',$content); // Remove all duplicate spaces
$content=preg_replace('/[^a-zA-Z\s]/','',$content); // Remove all non-letters
$content=trim($content);
$content=explode(' ',$content);
Run Code Online (Sandbox Code Playgroud)
有些值仍然是空白:
例如
$content[123] = '';
Run Code Online (Sandbox Code Playgroud)
我是否理解错误?肯定应该没有吧?
伙计们,我有一根绳子Model.Products[i].Description。长度未知。
我只想将它的前 60 个字符放在变量中。
var data = Model.Products[i].Description;
var temp = string.Join(string.Empty,data.Take(60));
Run Code Online (Sandbox Code Playgroud)
给我一个空值异常错误。我做错了什么 ?
有什么帮助吗?
这就是我想使用的查询。我认为更容易看看它并看看我哪里错了:
UPDATE * FROM 'catalog_product_entity_varchar'
SET TRIM(LEADING '0' FROM 'value')
WHERE 'attribute_id' = '176';
Run Code Online (Sandbox Code Playgroud)
因此,在我的表中,有很多 attribute_id = 176 的行,并且“value”列有很多前导 0。当 attribute_id 为 176 时,我想从值中删除所有前导 0。
这有点超出我的范围,但它似乎比尝试更新任何其他方式更快。
我有一个 CSV 文件,某些列中有很多尾随空格,因此我尝试编写一个简单的 Windows 窗体应用程序,该应用程序循环遍历 CSV 中的所有行并删除尾随空格。我认为我还很远,但我有一种感觉,C# 将其视为一行:
"Lorem ipsum dolor sit amet","Default ",9999,1,"base "
Run Code Online (Sandbox Code Playgroud)
虽然它应该将其视为一行:
"Lorem ipsum dolor sit amet"
Run Code Online (Sandbox Code Playgroud)
这是我现在的代码:
String path = @"C:\Users\me\Documents\test.csv";
string[] allLines = File.ReadAllLines(path);
using (StreamWriter sw = new StreamWriter(path))
{
foreach (string line in allLines)
{
if (!string.IsNullOrEmpty(line) && line.Length > 1)
{
line.TrimEnd(' ');
sw.WriteLine(line);
//sw.WriteLine(line.TrimEnd(' '));
}
}
}
Console.WriteLine(allLines);
Console.WriteLine("Done");
Run Code Online (Sandbox Code Playgroud)
我如何确保我的 CSV 文件是这样的:
"Lorem ipsum dolor sit amet ","Default ",9999,1,"base "
"simple","Default ",9999,1," base"
"test ","Default ",9999,1,"base"
Run Code Online (Sandbox Code Playgroud)
运行如下 C# 代码后会出现(因此末尾和开头没有空格): …
例如,我得到了很长的数字 1517778188788。我如何从该数字中获取前 6 位数字,例如 151777 并修剪其他数字?
我有一个 JSON.TEXT (https://godoc.org/github.com/jmoiron/sqlx/types#JSONText),我需要将其转换为字符串列表。例如,如何转换
`["equals", "less than"]` // JSON.TEXT type
Run Code Online (Sandbox Code Playgroud)
到
["equals", "less than"] // list of strings
Run Code Online (Sandbox Code Playgroud)
我试图通过使用string()、修剪[和]括号并将它们连接起来来显式转换 JSON.TEXT 类型,但我最终得到了一个带有奇怪反斜杠的字符串数组:
["\"equal to\"", " \"less than equal to\""]
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以实现此目的,或者如何摆脱反斜杠?
为什么字符串修剪对 Common Lisp 中的全局变量不起作用?
(defvar *whitespaces* '(#\Space #\Newline #\Backspace #\Tab
#\Linefeed #\Page #\Return #\Rubout))
(defvar *str* "Hello World")
(defun trim (s)
(string-trim *whitespaces* s))
(print (trim *str*))
;; output "Hello World"
Run Code Online (Sandbox Code Playgroud) Let category = "Baby Dress"
Run Code Online (Sandbox Code Playgroud)
我希望它被空格和文本修剪成小写。输出为“babydress”。我使用了以下代码。但它返回“婴儿礼服”。
category.trim(" ").toLowerCase()
Run Code Online (Sandbox Code Playgroud)
我需要了解为什么它没有按照我的预期进行,以及有哪些方法可以做到这一点。
我需要访问java源文件,我使用String的方法trim()来删除任何前导和尾随空格.但是代码是一些范围,例如:
if(name.equals("joe")){
System.out.println(name);
}
Run Code Online (Sandbox Code Playgroud)
打印声明的空格不会被完全删除.有没有办法能够删除这些白色空间吗?
谢谢
编辑:我确实使用了一个新变量:
String n = statements.get(i).toString().trim();
System.out.println(n);
Run Code Online (Sandbox Code Playgroud)
但输出仍然如下:
System.out.println("NAME:" + m.getName());
BlockStmt bs = m.getBody();
List<Statement> statements = bs.getStmts();
for (int i = 0; i < statements.size(); i++) {
if ((statements.get(i).toString().trim().contains(needed)) & (statements.get(i).toString().trim().length() == needed.length())) {
System.out.println("HEREEEEEEEEEEEEEEEEEEEEEEEEEE");
}
}
Run Code Online (Sandbox Code Playgroud)
一些字符串仍然预先包含空格