short

Short Text, PHP

拜拜、爱过 提交于 2019-11-30 15:56:41
问题 I got this function: function shorter($text, $chars_limit) { if (strlen($text) > $chars_limit) return substr($text, 0, strrpos(substr($text, 0, $chars_limit), " ")).'...'; else return $text; } and if I use echo shorter($input, 11) it works ok, but if there are some white spaces in the input, otherwise for the input looking like: wwwwwwwwwww The function will change this into: ... (3 dots). I wan't it to be changed into something like this: www ... Have you got any ideas how to rebuild this

Good way to convert between short and bytes?

烂漫一生 提交于 2019-11-30 15:07:04
问题 I need to take pairs of bytes in, and output shorts, and take shorts in and output pairs of bytes. Here are the functions i've devised for such a purpose: static short ToShort(short byte1, short byte2) { short number = (short)byte2; number <<= 4; number += (short)byte1; return number; } static void FromShort(short number, out byte byte1, out byte byte2) { byte byte2 = (byte)(number >> 4); short tempByte = (short)byte2 << 4; byte byte1 = (byte)(number - tempByte); } I think this is correct but

java short,integer,long performance

霸气de小男生 提交于 2019-11-30 14:46:11
问题 I read that JVM stores internally short, integer and long as 4 bytes. I read it from an article from the year 2000, so I don't know how true it is now. For the newer JVMs, is there any performance gain in using short over integer/long? And did that part of the implementation has changed since 2000? Thanks 回答1: long 64 –9,223,372,036,854,775,808 to 9 ,223,372,036,854,775,807 int 32 –2,147,483,648 to 2,147,483,647 short 16 –32,768 to 32,767 byte 8 –128 to 127 Use what you need, I would think

Short Text, PHP

ぐ巨炮叔叔 提交于 2019-11-30 14:44:29
I got this function: function shorter($text, $chars_limit) { if (strlen($text) > $chars_limit) return substr($text, 0, strrpos(substr($text, 0, $chars_limit), " ")).'...'; else return $text; } and if I use echo shorter($input, 11) it works ok, but if there are some white spaces in the input, otherwise for the input looking like: wwwwwwwwwww The function will change this into: ... (3 dots). I wan't it to be changed into something like this: www ... Have you got any ideas how to rebuild this script? Thank you in advance. Im assuming you just want to take an input. If it is longer than X then cut

Good way to convert between short and bytes?

允我心安 提交于 2019-11-30 13:23:30
I need to take pairs of bytes in, and output shorts, and take shorts in and output pairs of bytes. Here are the functions i've devised for such a purpose: static short ToShort(short byte1, short byte2) { short number = (short)byte2; number <<= 4; number += (short)byte1; return number; } static void FromShort(short number, out byte byte1, out byte byte2) { byte byte2 = (byte)(number >> 4); short tempByte = (short)byte2 << 4; byte byte1 = (byte)(number - tempByte); } I think this is correct but i'm not sure. If this isn't the right way to do it, what is? is there a way to do this already in the

java short,integer,long performance

谁说我不能喝 提交于 2019-11-30 12:00:54
I read that JVM stores internally short, integer and long as 4 bytes. I read it from an article from the year 2000, so I don't know how true it is now. For the newer JVMs, is there any performance gain in using short over integer/long? And did that part of the implementation has changed since 2000? Thanks JonH long 64 –9,223,372,036,854,775,808 to 9 ,223,372,036,854,775,807 int 32 –2,147,483,648 to 2,147,483,647 short 16 –32,768 to 32,767 byte 8 –128 to 127 Use what you need, I would think shorts are rarely used due to the small range and it is in big-endian format. Any performance gain would

Java instantiate Short object in Java

◇◆丶佛笑我妖孽 提交于 2019-11-30 07:56:47
问题 I was wondering why we can do: Long l = 2L; Float f = 2f; Double d = 2d; or even Double d = new Double(2); and not Short s = 2s; //or whatever letter it could be nor Short s = new Short(2); //I know in this case 2 is an int but couldn't it be casted internally or something? Why do we need to take the constructors either with a String or a short. 回答1: But you can do this: Short s = 2; Or this: Short s = new Short((short)2); Or this: Short s = new Short("2"); Any of the above will work as long

Why can I assign an integer literal to a short type variable but not to a short type method parameter?

蹲街弑〆低调 提交于 2019-11-30 06:45:20
Why can I do this: short a = 5; But not this: void setNum(short a); setNum(5); It throws: Possible lossy conversion from int to short I understand that 5 is an integer literal and you have to cast it. I also understand that if the value is not a constant then is obvious that it needs to throw that error because maybe the value reaches the limit of a short type. But why if the compiler knows I'm passing a constant that a short can hold (as in the assignment) it doesn't let it compile? I mean, what is the difference between them? In order to understand why the assignment type-conversion works

Batch parameter %~s1 gives incorrect 8.3 short name

半腔热情 提交于 2019-11-30 04:05:46
问题 I'm trying to write a batch file in Windows XP that takes in a fully-qualified path name and outputs the 8.3 short name version... @echo off echo "%~s1" I have come across one particular case where this outputs an incorrect path and file... C:\>test.bat "C:\Documents and Settings\angus\Local Settings\Temporary Internet Files\Content.IE5\2JSTM34V\62[1].ja2" "C:\DOCUME~1\angus\LOCALS~1\TEMPOR~1\Content.IE5\2JSTM34V\62_1_~1.JA2M34V\62[1].ja2" Note that the above output ("C:\DOCUME~1\angus\LOCALS

How to get long URL from short URL?

元气小坏坏 提交于 2019-11-30 00:56:15
Using Ruby, how do I convert the short URLs (tinyURL, bitly etc) to the corresponding long URLs? I don't use Ruby but the general idea is to send an HTTP HEAD request to the server which in turn will return a 301 response (Moved Permanently) with the Location header which contains the URI. HEAD /5b2su2 HTTP/1.1 Host: tinyurl.com Accept: */* RESPONSE: HTTP/1.1 301 Moved Permanently Location: http://stackoverflow.com Content-type: text/html Date: Sat, 23 May 2009 18:58:24 GMT Server: TinyURL/1.6 This is much faster than opening the actual URL and you don't really want to fetch the redirected URL