multiline

Detect where Android's TextView would insert a line break

风格不统一 提交于 2019-12-05 08:12:35
I have a rectangular tile, and I want to fit an image and some text into it. The image must not overlap the text, and the sizes of the image and the text can vary. The process must be hand-coded, since we have to fine-tune it according to our client's needs. I tried the approach of first measuring the rendered text bounds using getTextBounds() or measureText() and then adapting the font size and the image size so they don't overlap. This works fine if the text is only on one line. But if TextView wraps the text onto multiple line, I cannot predict the text bounds, since I don't know where

What's the simplest way to return the first line of a multi-line string in Perl?

[亡魂溺海] 提交于 2019-12-05 01:42:36
When I say simple, I mean, within an expression, so that I can stick it in as a value in a hash without preparing it first. I'll post my solution but I'm looking for a better one that reminds me less of VB. :) How about ( split /\n/, $s )[0] ? You don't have to worry about \n being not cross-platform because Perl is clever enough to take care of that . This isn't as simple as you like, but being simple just to be short shouldn't always be the goal. You can open a filehandle on a string (as a scalar reference) and treat it as a file to read the first line: my $string = "Fred\nWilma\Betty\n";

Split string by delimiter

天涯浪子 提交于 2019-12-05 01:30:28
I really can't find this answer... I have multiline NSString called myString in XCode, and it is a HTML code. I need to navigate the string by lines, for example: myString = @"<html>" "<body>" "<head><title>My Page</title>"; How can I access line per line? like: LineOne = myString.Lines[0]; LineTwo = myString.Lines[1]; How can I do something like that in XCode??? I need something like the Memo component in Delphi... The most html strings will have (mostly invisible) newline delimiters for separating the line NSArray *lines = [myHtmlString componentsSeparatedByString: @"\n"]; NSString *lineOne

Correct way to put long function calls on multiple lines

混江龙づ霸主 提交于 2019-12-05 00:54:27
I have a long function, as seen below: hash_correct = hashlib.md5(salt + password)).digest().encode("base64") I'd like to split it up into two lines but am not sure of the correct way to do this in Python? Thanks. The coding guidelines limiting length of lines is there, in part, to make the code more readable. In your case of chained method calls, the meaning is not clear. You should pick some temporary variable names for the intermediate values so that a reader of the code can understand the chain easily. One example might be: safe_md5 = hashlib.md5(salt + password) crypto_hash = safe_md5

Paste multiline text in input type text (not textarea)

五迷三道 提交于 2019-12-05 00:38:31
问题 I have a input type text where the users enter numeric codes separated by , or by - (to make a range). I'd like to allow the user of my site to paste a codes list. I've already managed to bind paste event (with jQuery) and parse the input string removing spaces and everything. The problem starts when the user codes list is multiline. I haven't found any way to manipulate that text before the browsers attempts to insert it into the input, so the string is truncated at the end of the first line

Why are multi-line comments in flex/bison so evasive?

假如想象 提交于 2019-12-04 23:33:57
I'm trying to parse C-style multi-line comments in my flex (.l) file: %s ML_COMMENT %% ... <INITIAL>"/*" BEGIN(ML_COMMENT); <ML_COMMENT>"*/" BEGIN(INITIAL); <ML_COMMENT>[.\n]+ { } I'm not returning any token and my grammar (.y) doesn't address comments in any way. When I run my executable, I get a parse error: $ ./a.out /* abc def Parse error: parse error $ echo "/* foo */" | ./a.out Parse error: parse error (My yyerror function does a printf("Parse error: %s\n"), which is where the first half of the redundant error message comes from). I can see why the second example fails since the entirety

make nstextfield single line

早过忘川 提交于 2019-12-04 22:59:53
how to make NSTextField really single line? I created a text field programmatically. when the return key is pressed, all text is selected. but I can still paste multiple lines of text. And when I press Arrow-right or Arrow down, it scroll to the next line. There aren't these issues if I use IB and set the "use single line mode", but I couldn't find the right method to set it programmatically. Peter Hosey Have you tried telling the field's cell to set whether it uses single-line mode ? [myTextField.cell setUsesSingleLineMode:YES]; This works for me when programmatically creating controls:

Regular expression to grab form tag content doesn't work

喜你入骨 提交于 2019-12-04 17:19:12
I am trying to grab contents/tags inside form tag using preg_match_all, here is the regular expression /<form\b[^>]*>(.*?)<\/form>/i But i wonder, why it doesn't work! Any idea? By default, the . (DOT) does not match line breaks. If you enable DOT-ALL with the s modifier, it does match those chars: /<form\b[^>]*>(.*?)<\/form>/is Realize that you won't be able to match something like: <form> ... <!-- </form> --> ... </form> to name just one of the possibilities. marcog Don't use regular expressions to parse HTML. Use an HTML parser. 来源: https://stackoverflow.com/questions/4288102/regular

Match Multiple Line Regex Javascript

蹲街弑〆低调 提交于 2019-12-04 15:37:26
I have beat my head against the wall for the better part of the night so I am looking to the stackoverflow Gods to help with this. I have a text string that I am attempting to parse into an array. See the example below: Name: John Doe Address: 123 W Main Street City: Denver Name: Julie Smith Address: 1313 Mockingbird Lane City: Burbank What I would like to get is an array that looks like this: [Name: John Doe Address: 123 W Main Street City: Denver, Name: Julie Smith Address 1313 Mockingbird Lane City: Burbank] I started with the following regex and it works fine in regexpal: (Name.+)(\n.*){2}

Why doesn't Java support multi-line strings? [closed]

隐身守侯 提交于 2019-12-04 15:20:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Why doesn't Java support multi-line strings? I know they dont, but I dont know why. Is there a good reason? Several other languages have this capability, even older ones, so why doesnt Java? As far as I know (not very far) it shouldnt be too had to add this functionality to