我相信我们所有人都在Facebook状态(或其他地方)看过省略号,然后点击"显示更多"并且只有另外两个字符左右.我猜这是因为懒惰的编程,因为肯定有一种理想的方法.
我将细长的字符[iIl1]称为"半字符",但是当它们几乎不隐藏任何字符时,这并不会使省略号看起来很傻.
有理想的方法吗?这是我的:
/**
* Return a string with a maximum length of <code>length</code> characters.
* If there are more than <code>length</code> characters, then string ends with an ellipsis ("...").
*
* @param text
* @param length
* @return
*/
public static String ellipsis(final String text, int length)
{
// The letters [iIl1] are slim enough to only count as half a character.
length += Math.ceil(text.replaceAll("[^iIl]", "").length() / 2.0d);
if (text.length() > length)
{
return text.substring(0, length - …Run Code Online (Sandbox Code Playgroud) 像这样的数据库表
============================
= suburb_id | value
= 1 | 2
= 1 | 3
= 2 | 4
= 3 | 5
Run Code Online (Sandbox Code Playgroud)
查询是
SELECT COUNT(suburb_id) AS total, suburb_id
FROM suburbs
where suburb_id IN (1,2,3,4)
GROUP BY suburb_id
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此查询时,当suburb_id = 0时它不会给COUNT(suburb_id)= 0因为在郊区表中没有suburb_id 4,我希望这个查询为suburb_id = 4返回0,就像
============================
= total | suburb_id
= 2 | 1
= 1 | 2
= 1 | 3
= 0 | 4
Run Code Online (Sandbox Code Playgroud) 我一直想知道为什么这么多Java开发人员使用".do"作为其Web控制器(MVC)资源的扩展.示例:http://example.com/register.do
它似乎甚至不是特定于框架,因为我在Spring MVC和Struts项目中看到过它.这个".do"扩展实践来自何处.为什么这样做而不是没有延期?我觉得我错过了关于这个的Java世界备忘录.
我个人不喜欢延伸.
到处都是,特别是在DBI中,我看到这个消息一直出现.令人困惑的是,因为首先想到的是我传递函数的参数被设置为undef(或类似的东西),但显然不是这样.
给定一个模块和相应的脚本......
模块: ./lib/My/Module.pm
package My::Module;
use strict;
use warnings;
sub trim {
my $str = shift;
$str =~ s{ \A \s+ }{}xms; # remove space from front of string
$str =~ s{ \s+ \z }{}xms; # remove space from end of string
return $str;
}
Run Code Online (Sandbox Code Playgroud)
脚本: ./test.pl
#!/usr/bin/perl
use strict;
use warnings;
use My::Module qw(trim);
print $My::Module->trim( " \t hello world\t \t" );
Run Code Online (Sandbox Code Playgroud)
我收到了错误消息
无法在./text.pl第7行的未定义值上调用方法"trim".
事实上,如果我调用$My::Module->notamethod( "hello world" );它会产生类似的错误.
上面的脚本/模块出了什么问题?
这个错误Can't call method “X” on an …
我有一个字符串"foo_bar"和"foo_foo_bar".如何"_bar"从字符串中删除最后一个?所以我留下了"foo"和"foo_foo".
我们正在使用Web浏览器控件开发WPF应用程序.当用户拖动窗口时,Web浏览器在拖动时滞后于窗口.
有谁知道如何解决这个问题?如果不这样做,有没有人知道网页浏览器控件本身的替代品?
谢谢!
我正在运行以下行:
mysql_query("INSERT INTO tags
SET tag = '".$onesearch."',
SET date = '".date('d-m-Y')."'") or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
......并且它的节食说:
您的SQL语法有错误; 查看与您的MySQL服务器版本对应的手册,以便在第1行的'SET date = '29 -08-2010''附近使用正确的语法
我无法弄清楚出了什么问题.
如果我没有在Codeigniter的URL中提供值,它将显示一个PHP错误,说它缺少函数调用的参数.我根本不希望它显示出来.如果URL中没有参数,则应该重新路由到其索引函数.我该如何防止这种情况发生?
例如,www.example.com/profile/id/45
任何人都会像这样猜测并输入"www.example.com/profile/id"
会产生错误.我该如何预防呢?我试过,"如果(!isset($ id))"但它在达到该条件之前产生了错误.
你可以将数字1到16排成一个圆圈,使得相邻两个数字的总和是一个完美的正方形吗?如果是,如何,如果不是,为什么不呢?你能写一个程序来解决这个问题吗?