why this single charactor has 122 byte? - string

I meet a stange charactor,It has 122 bytes.
<script>
var pig ="ฏ๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎๎ํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํํ";
alert(pig.length) ;
</script>
The result is 122! oh,my god.
It make the web page disordered.

Its not a character its a string containing 122 characters, its actually 366 bytes in size. the string is made up of 3 characters, 1 ฏ some ๎ and the rest in ํ. I think they're Thai characters since chrome asks if I want to translate it from Thai.
see http://jsfiddle.net/mowglisanu/6b6VY/

Related

Extract Arabic Text using iTextsharp get number only?

I try To extract Arabic Text from PDF file but it extract only number and the result like this :
: 7234569 1439/08/07 : : 1 2375173941 14 08 6 39266 1050672243 2280 30 400 24 415 24 15 720 30 402 30 499 14 07 1 610117038085 0 1069508677 0 :
My code :
public static string GetTextFromAllPages(string pdfPath) {
PdfReader reader = new PdfReader(pdfPath);
string result = null ;
//for (int i = 1; i <= reader.NumberOfPages; i++)
result = PdfTextExtractor.GetTextFromPage(reader, 1, new LocationTextExtractionStrategy()); return result;
}
Any help Please?
The embedded font for Arabic glyphs in your PDF contains this ToUnicode CMap:
/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
/CMapName /Adobe-Identity-UCS def
/CMapType 2 def
1 begincodespacerange
<0000> <FFFF>
endcodespacerange
endcmap
CMapName currentdict /CMap defineresource pop
end
end
According to ISO 32000-1, section 9.10.3 ToUnicode CMaps:
It shall use the beginbfchar, endbfchar, beginbfrange, and endbfrange operators to define the mapping from character codes to Unicode character sequences expressed in UTF-16BE encoding.
Unfortunately your CMap does not use these operators at all and, therefore, does not define any mappings to Unicode.
Furthermore the font has an Encoding of Identity-H and its descendant CIDFont has a ROS Adobe-Identity-0 which means that character code, CID, and GID values are equal for a character but doesn't imply any mapping of them to Unicode.
Thus, the font is missing the information required for text extraction according to ISO 32000-1 section 9.10.2 Mapping Character Codes to Unicode Values.
(In such a situation text extractors can only guess, and such guesswork usually only works for a special type of documents the extractor is optimized for. You might want to try to enhance iText to be able to guess correctly in your case but that will require you to study the PDF specification, the iText text extraction code, and your sample files in detail.)
By the way, a good first test whether text extraction is feasible is to open the PDF in Adobe Reader and to copy and paste the text in question to an editor or word processor. If this does not work (and in the case at hand it does not work), chances are that the file does have incomplete or misleading information for text extraction (or none at all).

How can I check that my username is string

I created loggin panel and now i wanna check that username is only string. In other case i want to return "Bad username". So How can I check that textfield is only string ?
I am not sure what exactly you mean by if the username is a string?
If by string, you mean that your username consists of only characters i.e. A-Z (or a-z). You can check if each character in your username have the ascii value between 65 to 90 (for A-Z) or 97 to 122 (for a-z). If you want to allow any other characters such as underscore (ascii 242), add that also to the test.

String Concatenation

As I asked in my previous question(Link) about concatenating a multipart string of variable lengths, I used the method answered there by rkhayrov and now, my function looks like this:
local sToReturn = string.format( "\t%03s\t%-25s\t%-7s\n\t", "S. No.", "UserName", "Score" )
SQLQuery = assert( Conn:execute( string.format( [[SELECT username, totalcount FROM chatstat ORDER BY totalcount DESC LIMIT %d]], iLimit ) ) )
DataArray = SQLQuery:fetch ({}, "a")
i = 1
while DataArray do
sTemp = string.format( "%03s\t%025s\t%-7d", tostring(i), DataArray.username, DataArray.totalcount )
sToReturn = sToReturn..sTemp.."\n\t"
DataArray = SQLQuery:fetch ({}, "a")
i = i + 1
end
But, even now, the value of score is still not following the order as required. The max length of username is 25. I've used %025s inside the while loop because I want the usernames to be right-justified, while the %-25s is to make the word UserName centre justified.
EDIT
Current output:
Required Output:
Displaying the list of top 5 chit-chatters.
S. No. UserName Score
1 Keeda 9440
2 _2.2_™ 7675
3 aim 7057
4 KGBRULES 6770
5 Guddu 6322
I think it's because of difference in fonts, but since most of the clients have Windows 7 default fonts(Tahoma/Verdana at 11px), I need optimum result for at-least that.
I think it's because of difference in fonts
It is. string.format formats by inserting whitespace. That only works for a fixed width fonts (i.e. all characters have the same width, including whitespace).
since most of the clients have Windows 7 default fonts(Tahoma/Verdana at 11px)
In what? How are they viewing your output? Do you write it to a textfile, that they then open in the editor of their choice (likely Notepad)? Then this approach will simply not work.
Don't know enough about your output requirements to steer you any futher, but it's worth noting that everyone has a browser so HTML output is very portable.
string.format doesn't truncate - the width of the field is minimum, not maximum. You'll have to truncate the strings to 25 characters yourself with something like DataArray.username:sub(0,25).
I'd remove the tabs from the string.format; and use the justification provided by %25s only. Won't be perfect but will probably be closer.
Use a fixed-width font if you can.

Eggplant/Sensetalk parsing and separating a string with capitalized words

I'm in need of the ability to parse and separate a text string using Sensetalk (the scripting language the Eggplant GUI tester uses). What I'd like to be able to do is provide the code a text string:
Put "MyTextIsHere" into exampleString
And then have spaces inserted before every capital letter save for the first, so the following is then stored in exampleString:
"My Text Is Here"
I basically want to separate the string into the words it contains. After searching the documentation and the web, I'm no closer to finding a solution to this (I agree, it would be far easier in a different language - alas, not my choice).
Thank you in advance to anyone who can provide some insight!
See question at http://www.testplant.com/phpBB2/viewtopic.php?t=2192.
With credit to Pamela at TestPlant forums:
set startingString to "HereAreMyWords"
set myRange to 2 to the number of characters in startingString // The range to iterate over– every character except the first
Put the first character in startingString into endString // The first character isn't included in the repeat loop, so you have to put it in separately
repeat with each character myletter of characters myRange of startingString
if charToNum(myLetter) is between 65 and 90 // if the character's unicode number is between 65-90...
Put space after endString
end if
Put myLetter after endString
end repeat
put endString
or you could do it this way:
Put "MyTextIsHere" into exampleString
repeat with each char of chars 2 to last of exampleString by reference
if it is an uppercase then put space before it
end repeat
put exampleString

Drupal Comment Form Missing

I've inherited a Drupal 6 project and I am in need of a comment form on one of my pages. The module is enabled and the content type is set to allow for comments.
The permissions are set as follows:
Anonymous User: Access Comments, Post Comments
Authenticated User:
Access Comments, Post Comments
Content Admin: Access Comments,
Administer Comments, Post Comments, Post Comments Without Approval
A link displays below the page contents, "Add new comment." Clicking this link takes me to the URL comment/reply/28#comment-form, which is displaying the same content and nothing new. I believe there should be a form displaying on this page, but I cannot for the life of me figure out what I am missing.
The site is on a custom theme - is there somewhere that I need to make a PHP call to show the form on a page? I searched through a couple of the other themes(that apparently come standard with Drupal) and could find no reference other than comment.tpl.php, which is identical to the one in this custom theme.
EDIT: Per Oswald's suggestion in an answer below, I installed the Theme Developer add-on to try to track down what is going on. The results of going into devel mode on the page in question are as follows:
... (Object) stdClass
nid (String, 2 characters ) 28
type (String, 5 characters ) story
language (String, 0 characters )
uid (String, 1 characters ) 1
status (String, 1 characters ) 1
created (String, 10 characters ) 1311112998
changed (String, 10 characters ) 1311113045
comment (String, 1 characters ) 2
promote (String, 1 characters ) 0
moderate (String, 1 characters ) 0
sticky (String, 1 characters ) 0
tnid (String, 1 characters ) 0
translate (String, 1 characters ) 0
vid (String, 2 characters ) 28
revision_uid (String, 1 characters ) 1
title (String, 12 characters ) testimonials
body (String, 2076 characters ) Lorem Ipsum blah blah blah
teaser (String, 554 characters ) Lorem Ipsum blah blah blah
log (String, 0 characters )
revision_timestamp (String, 10 characters ) 1311113045
format (String, 1 characters ) 1
name (String, 8 characters ) blahblahblah
picture (String, 0 characters )
data (String, 72 characters ) a:1:{s:13:"form_build_id";s:37:"form-4fad331ed7...
last_comment_timestamp (String, 10 characters ) 1311112998
last_comment_name (NULL)
comment_count (String, 1 characters ) 0
taxonomy (Array, 0 elements)
The only thing that stood out to me was the data section, the full contents of which are: a:1:{s:13:"form_build_id";s:37:"form-4fad331ed7e2000d316142aaf87c302f";}.
The parents of the page /comment/reply/28#comment-form are theme_markup < node < page. The candidate function names are templatename_markup < phptemplate_markup < theme_markup.
The page template that is used to render the page (usually page.tpl.php) should know a variable called $content. This variable should contain the rendered node and the rendered comment form.
Use the Theme developer module to find out which page template is used to render comment/reply/28#comment-form. Examine that template file to find out whether $content is actually used by the template.
Have you checked the theme's configuration? Some themes have an option to disable the display of the comment form (and other things).
I ended up re-writing the template from the ground up and got the comments working. No explanation as to what was wrong with it initially.
I was working on a site that someone else had put up some years ago and was facing this problem too. After testing with other themes and making sure all the settings were right, I was sure it was a conflict with a module. And it sure was, the original web developer had enabled Commentsblock which disabled the comments on node template and made them available only in a block.
Should have gone through the modules first, that was pretty obvious..

Resources