substr

Find longest repeating string based on input in perl (using subroutines)

ぃ、小莉子 提交于 2019-12-12 05:49:25
问题 So I'm trying to find the longest repeat for a specific pattern thats given. My code so far looks like this, and is fairly close, however it does not fully give the wanted result: use warnings; use strict; my $DNA; $DNA = "ATATCCCACTGTAGATAGATAGAATATATATATATCCCAGCT" ; print "$DNA\n" ; print "The longest AT repeat is " . longestRepeat($DNA, "AT") . "\n" ; print "The longest TAGA repeat is " . longestRepeat($DNA, "TAGA") . "\n" ; print "The longest C repeat is " . longestRepeat($DNA, "C") . "\n

Counting words in PHP

ⅰ亾dé卋堺 提交于 2019-12-12 05:25:34
问题 I have a problem with counting words in PHP, this is my code: $word=substr(stripslashes(strip_tags($row['short_story'], '<a></a>')), 0,100 )."..."; $tpl->set( '{word}',$word); on that code i just can show URL links in my result, i need to show complete style and HTML codes, so i changed to this: $word = substr( stripslashes (strip_tags($row['short_story'], '<a><b><i><u><br></a><div></div>')), 0,400 )."..."; i changed this: <a></a> to: <a><b><i><u><br></a><div></div> But problem is, i have to

Replace substring with nothing

夙愿已清 提交于 2019-12-12 03:38:56
问题 How can I replace everything starting with the _ with just nothing? Here is a simple data frame d <- data.frame(a = c("A_foo1", "B_foo2", " _foo3")) I want d to look like: a A B " " 回答1: a <- c("A_foo1", "B_foo2", " _foo3") gsub("_.*", "", a) #[1] "A" "B" " " 来源: https://stackoverflow.com/questions/13570312/replace-substring-with-nothing

PHP: How to find the beginning and end of a substring in a string?

耗尽温柔 提交于 2019-12-12 01:18:45
问题 This is the content of one mysql table field: Flash LEDs: 0.5W LED lamps: 5mm Low Powers: 0.06W, 0.2W Remarks(1): this is remark1 ---------- Accessories: Light Engine Lifestyle Lights: Ambion, Crane Fun Office Lights: OL-Deluxe Series Street Lights: Dolphin Retrofits: SL-10A, SL-60A Remarks(2): this is remark2 ---------- Infrared Receiver Module: High Data Rate Short Burst Optical Sensors: Ambient Light Sensor, Proximity Sensor, RGB Color Sensor Photo Coupler: Transistor Remarks(3): this is

Show only five first lines from text file

陌路散爱 提交于 2019-12-11 19:19:01
问题 I have this code (from SteAp): <?php $file = fopen("news/news_2013.txt", "r"); $i = 0; while (!feof($file)) { $posts[] = fgets($file); } fclose($file); foreach ($posts as $rawPost ){ $datePart = substr( $rawPost, 0, 19 ); $newsPart = substr( $rawPost, 20, 10000 ); echo $datePart . ': ' . $newsPart . '<br />'; } ?> I use it here: http://flamencopeko.net/news. Works perfect. I'm trying to make a version for the main page that shows only the five newst lines. Like this: http://flamencopeko.net

JS验证身份证号码是否合法

时光怂恿深爱的人放手 提交于 2019-12-11 18:09:47
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 现在经常会遇到让输入身份证号码的需求,那么我们应该如何验证身份证号码的合法性呢?今天我们来说一说验证的方法。 function checkIdcard(num){ num = num.toUpperCase(); //身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X。 if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) { alert('输入的身份证号长度不对,或者号码不符合规定!\n15位号码应全为数字,18位号码末位可以为数字或X。'); return false; } //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。 //下面分别分析出生日期和校验位 var len, re; len = num.length; if (len == 15) { re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/); var arrSplit = num.match(re); //检查生日日期是否正确 var dtmBirth = new Date('19' + arrSplit[2] + '/' +

Select without duplicate from a specific string/key

会有一股神秘感。 提交于 2019-12-11 16:48:50
问题 Thanks to @Ed Gibbs i managed to solve my first problem on this case (Select duplicate and keep the oldest (not based on ID)) I am now facing a new problem I can not solve. I have two tables, "domain" which is clear of duplicate and "email" which contains duplicate. In the first table i had a value called "creationdate" which i used as a filter. In the second table i don't have any filter but some informations could (i think) be used to act as a filter. Table domain : | domain | value 1 |

Last two letters of a user inputted string using substring (Java)

╄→尐↘猪︶ㄣ 提交于 2019-12-11 12:54:03
问题 I'm writing a program that generates star wars names. The user inputs their first, last, mother's maiden name, birth city, and first car and the program gives a star wars name. I need the last two characters* of the user inputted last name. I know I can use substring , but I cannot get anything to work. The best I have is: lastname.substring(lastname.length() -2) which gives the first two letters of the last name, and not the last. Also, I cannot use lastname.substr(-2) because substr for

Remove the punctuation mark with regular expression?

别说谁变了你拦得住时间么 提交于 2019-12-11 09:29:51
问题 I made this function to limit the length of a string in the output, /* limit the lenght of the string */ function limit_length($content, $limit) { # strip all the html tags in the content $output = strip_tags($content); # count the length of the content $length = strlen($output); # check if the length of the content is more than the limit if ($length > $limit) { # limit the length of the content in the output $output = substr($output,0,$limit); $last_space = strrpos($output, ' '); # add dots

PHP Substr Function Trimming Problem [duplicate]

你说的曾经没有我的故事 提交于 2019-12-11 08:25:40
问题 This question already has answers here : Why my php substr() shows obscure characters when cutting a text? (4 answers) Closed 5 years ago . I'm using below code for triming titles and show it recent posts section on my blog: <?php global $post; $releaseDate = get_post_meta($post->ID, "gosterim_tarihi", true); foreach( $images as $image ) { $title = get_the_title(); if (strlen($title) > 20) { $title = substr($title, 0, 20) . '…'; } $attachmentimage=wp_get_attachment_image_src( $image->ID,