我从textarea获取数据,用户必须在每行输入一个名称.该数据后来在回车时被拆分.有时用户可能会故意添加空行.如何检测这些行并删除它们?我正在使用PHP.我不介意使用正则表达式或其他任何东西.
数据不正确
Matthew
Mark
Luke
John
James
Run Code Online (Sandbox Code Playgroud)
正确的数据(注意删除空白行)
Matthew
Mark
Luke
John
James
Run Code Online (Sandbox Code Playgroud) bool Res = false;
DataView DV = new DataView(DT);
DV.RowFilter = "Trim(Originator)='"+OrginatorName.Trim()+"'";
if (DV.Count > 0)
{
Res = true;
}
Run Code Online (Sandbox Code Playgroud)
我需要从数据库中获取"Originator"并将其与OrginatorName进行比较以检查重复值.我需要在检查之前删除所有空格.
例如,该函数必须将"John Van"视为与"JohnVan"相同.我上面的代码不起作用.我怎样才能做到这一点?
我必须在C中编写快速右侧修剪功能.我的第一次尝试是:
void TrimRight( char *s )
{
char* pS;
if (!*s)
return;
if (!s)
return;
for ( pS = s + strlen(s) - 1; isspace(*pS) && (pS >= s); pS--)
{
pS[1] = '\0';
}
}
Run Code Online (Sandbox Code Playgroud)
第二次尝试:
void TrimRight( char *s )
{
if (!*s)
return;
if (!s)
return;
char* pS = s + strlen(s) - 1;
while ((*pS == ' ') && (pS > s))
{
(*pS--) = '\0';
}
}
Run Code Online (Sandbox Code Playgroud)
问题是:我在这里改进了内存访问吗?我怎样才能进一步优化它?如何优化内存访问?
更新:按顺序递增的扫描内存是否更快?
我需要找出从字符串的开头删除了多少个字符,这是textarea输入的值,所以我可以确定光标选择的新起始位置.
$.trim() 会做什么修剪,但我怎么能从一开始就知道有多少个字符?
将数据分配给开头有很多空格的变量,然后我做一个修剪以删除它,并希望回显应该是@的第一个字符.但是,回声没有显示任何内容.
$data = ' @ JWHS8282';
trim($data);
echo $data[0];
Run Code Online (Sandbox Code Playgroud) 如何在进行批量插入时修剪空白区域?我有如下样本数据:
| |100 |4000009|1000 |01 | |201004471| |28.01.1972|10.04.2012|300485|ABC 307.07B |01 | | |SSC |SSC |CA02 |00 | |0 |SESC |COM |01 |01 |00.00.0000|00.00.0000|FR1 |
Run Code Online (Sandbox Code Playgroud) 我正在使用C#.NET和Windows CE Compact Framework.我有一个代码,其中应该将一个字符串分成两个文本框.
textbox1 = ID
textbox2 = quantity
string BarcodeValue= "+0000010901321 JN061704Z00";
textbox1.text = BarcodeValue.Remove(0, BarcodeValue.Length - BarcodeValue.IndexOf(' ') + 2);
//Output: JN061704Z00
textbox2.text = BarcodeValue.Remove(10, 0).TrimStart('+').TrimStart('0');
//Output: should be 1090 but I am getting a wrong output: 10901321 JN061704Z00
//Please take note that 1090 can be any number, can be 999990 or 90 or 1
Run Code Online (Sandbox Code Playgroud)
有人可以帮我这个吗?:((
谢谢!!
需要格式化值,从最后切割零,这样:
3 => 3
3. => 3
3.0 => 3
3.00 => 3
3.000 => 3
3.009 => 3.009
3.003 => 3.003
3.01 => 3.01
3.10 => 3.1
3.16 => 3.16
Run Code Online (Sandbox Code Playgroud)
找到了这些Smarty修改器插件,它将完成这项工作{$ var | zero_cut:4}:
Source: http://www.smarty.net/forums/viewtopic.php?p=17482
vl@vl plugins $ cat modifier.zero_cut.php
<?php
/**
* Smarty insignificant zero cutter modifier plugin
*
* Type: modifier<br>
* Name: zero_cut<br>
* Purpose: Format string, representing float value with given
* number of digits after decimal point with deletion
* of insignificant zeros. …Run Code Online (Sandbox Code Playgroud) 我有一个表"partner_entries"有3列:our_ref | partner_ref | partner_tag其中所有3个字段构成主键.
我有一定数量的"重复"行,如下所示:
42 | abc | tag1
42 | abc | tag1
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,它并不是真的重复,因为在同一个单词后面有一个空格.我可以根据our_ref和partner_tag检索重复项,如下所示:
SELECT COUNT(*) AS nb_duplicates, our_ref, partner_tag
FROM partners_entries
GROUP BY our_ref, partner_tag
HAVING COUNT(*) > 1
Run Code Online (Sandbox Code Playgroud)
但是它也需要一些其中partner_ref确实不同的行,我只想选择其中partner_ref相同但后面有空格的那些,我该怎么做?
谢谢你的帮助
我是C#的新手,我想知道是否有一个函数来删除浮点数组末尾的特定值(0)?
例如:
float[] samples = {0.0, 4.0, 2.5, ..., 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
Run Code Online (Sandbox Code Playgroud)
通话结束后,我想要我的样品:
samples == {0.0, 4.0, 2.5, ..., 2.0}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助
trim ×10
php ×3
string ×3
c# ×2
.net ×1
arrays ×1
asp.net ×1
bulkinsert ×1
c++ ×1
dataview ×1
duplicates ×1
javascript ×1
jquery ×1
memory ×1
modifier ×1
mysql ×1
optimization ×1
regex ×1
rowfilter ×1
smarty ×1
sql ×1
sql-server ×1
templates ×1