知行社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2484|回复: 7
收起左侧

代码语法高亮显示效果

[复制链接]
知行 发表于 2011-10-13 12:01 | 显示全部楼层 |阅读模式
[code=C]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

int main(int argc, char** argv)
{
char *filename;
filename=new char[50];
printf("请输入文件名:");
gets(filename);
char *cpy;
cpy=new char[100];
strcpy(cpy,"copy ");
strcat(cpy,filename);
strcat(cpy," ");
char *disk;
disk=new char[10];
printf("请输入要复制到的盘符:");[/code]
 楼主| 知行 发表于 2011-10-13 12:03 | 显示全部楼层
[code=HTML]<STYLE type="text/css">
TD {
FONT-SIZE: 14px; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
</STYLE>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body style="background: #c7edcc; font-family: Helvetica">
<table cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR bgColor=#73a3d4 height=40>
<TD noWrap align=center width="100%" ><h3>SyntaxHighlighterToHtm</h3></TD>
</TR>
</table>
<pre class="brush: cpp;">[/code]
 楼主| 知行 发表于 2011-10-13 12:04 | 显示全部楼层
[code=C++]#include <cstdlib>
#include <iostream>
using namespace std;

int Fib(int n);

int main(int argc, char** argv)
{
int min,max;
cout<<"请输入数列区间"<<endl;
cin>>min>>max;
for(int i=min;i<=max;i++)
{
cout<<Fib(i)<<" ";
}
cout<<endl;
system("pause");
return 0;
}[/code]
 楼主| 知行 发表于 2011-10-13 12:06 | 显示全部楼层
[code=Java]// Demo one
public void batch_op_one() {

session = Jorm.getSession();
JdbcBatcher batcher = session.createBatcher();
batcher.addBatch("delete from t_id_auto");
batcher.addBatch("delete from t_incre");
batcher.addBatch("delete from t_user");
batcher.execute();

session.beginTransaction();
long start;
try {
start = System.currentTimeMillis();
String sql = "INSERT INTO t_user(sex,age,career,name,id) VALUES(?,?,?,?,?)";
for (int i = 0; i < 100000; i++) {
batcher.addBatch(sql, new Object[] {"男", Numbers.random(98), Strings.random(10), Strings.fixed(6), (i+1) });}
String sqlx = "INSERT INTO t_id_auto(name, id) VALUES(?, ?)";
for (int i = 0; i < 100000; i++) {
batcher.addBatch(sqlx, new Object[] {Strings.fixed(6), (i+1)});
if(i > 200) {
//Integer.parseInt("kkk");
}
}
batcher.execute();
System.out.println(System.currentTimeMillis() - start);
} catch (Exception e) {
session.rollback();
} finally {
session.endTransaction();
session.close();
}
}[/code]
 楼主| 知行 发表于 2011-10-13 12:07 | 显示全部楼层
[code=JavaScript]var tm_highlight = null;
function _highlight()
{
clearTimeout(tm_highlight);
tm_highlight = setTimeout('document.getElementById("oResult").innerHTML = ("<nobr>"+document.getElementById("oTxt").value.formatJS()+"</nobr>");', 1000);
}
//String.prototype.div = document.createElement('div');
String.prototype.toHtml = function () {
return this
.replace(/\&/g, '&')
.replace(/\</g, '<')
.replace(/\>/g, '>')
.replace(/\x20/g, ' ')
.replace(/(\r\n|\r|\n)/g, '<br>');
};
String.prototype.formatJS = function ()
{
var s = this;
var index = 0, brch=0;
var keywords = ['abstract','boolean','break','byte','case','catch','char','class','const','continue','default','delete','do','double','else','extends','false','final','finally','float','for','function','goto','if','implements','import','in','instanceof','int','interface','long','native','new','null','package','private','protected','public','return','short','static','super','switch','synchronized','this','throw','throws','transient','true','try','typeof','var','void','while','with'];
var objects = ['Anchor','anchors','Applet','applets','Area','Array','arguments','Button','Checkbox','Date','document','FileUpload','Form','forms','Frame','frames','Function','Hidden','history','Image','images','Link','links','Area','location','Math','MimeType','mimeTypes','navigator','options','Password','Plugin','plugins','Radio','Reset','RegExp','Select','String','Submit','Text','Textarea','window'];
var specials = ['prototype','callee','caller','apply','call','encodeURIComponent','decodeURIComponent','parseInt','parseFloat','__defineGetter__','__defineSetter__'];
var blocks = [];
var indent = "", indent_fix="";
s=s
.replace(/\t/g, ' ')
.replace(/\r\n|\r/g, "\n")
.replace(/(\/\/[^\n]*(\n|$)|\/\*(\*(?!\/)|[^\*])*\*+\/|\"(\\\"|\\\\|[^\"\n])*\"|\'(\\\'|\\\\|[^\'\n])*\'|([=!\(\:\{\[\;&|^]\s*)\/(\\.|[^\/\n])+\/[igm]*)/g,
function ($0)
{
var color = "#CCCCCC", ret = "'"; // comment
var kkk = $0;
if(kkk.charAt(0) == '"')
color = "#FF00FF"; // double quote
else if(kkk.charAt(0) == "'")
color = "#9900FF"; // single quote
else if(kkk.match(/^(?:[=!\(\:\{\[&|^]\s*)(\/(\\.|[^\/\n])+\/[igm]*$)/))
{
ret = kkk.replace(/^([=!\(\:\{\[&|^]\s*)(\/(\\.|[^\/\n])+\/[igm]*$)/, "$1'");
kkk = kkk.replace(/^([=!\(\:\{\[&|^]\s*)(\/(\\.|[^\/\n])+\/[igm]*$)/, "$2");
color = "#6666CC"; // regexp
}
blocks[blocks.length] = "<font color="+color+">"+kkk.toHtml()+"</font>";
return ret;
})
// ;alert(blocks);s=s
.replace(/(\}?[\n ]*;[\n ]*)/g, function ($0,$1){return $1.replace(/[\n ]/g, '')+"\n";})
.replace(/\b(else)\b/g, "$1\n")
.replace(/\b((case|default)[^:]*\:)/g, "$1\n")
.replace(/(\{[\n ]*)((([A-Za-z\$\_][0-9A-Za-z\$\_]*|`)[\n ]*\:[\n ]*[^,\}]+,?)+)([\n ]*\})/g, function ($0,$1,$2,$3,$4,$5)
{
return $1+$2.replace(/[\n ]+/g, ' ').replace(/(([A-Za-z\$\_][0-9A-Za-z\$\_]*|`)\:[^,\}]+,?)/g, "$1\n")+$5;
})
.replace(/[\n ]*(\{|\};?)[\n ]*/g, function ($0, $1)
{
if($1.charAt(0) == '}') brch--;
var ss = "\n";
for(var i=0;i<brch;i++) ss += " ";
if($1 == '{') brch++;
return ss+$1+"\n";
})
.replace(/[\n ]*\{[\n ]*\}/g, '{}')
.replace(/^[ ]*([^\{\}])/g, "$1")
.replace(/(\n\s*for\b[^\n]*\;\s*)\n/g, '$1')
.replace(/(\n\s*for\b[^\n]*\;\s*)\n/g, '$1')
.replace(/\n\s*(for|while|if|switch)\b[^\n]*; *\n/g, function ($0, $1)
{
var le = 0;
for(var i=0;i<$0.length;i++)
if($0.charAt(i) == '(') le++; else if($0.charAt(i) == ')'){le--; if(le == 0)return $0.substr(0,i+1)+"\n"+$0.substr(i+1,$0.length);}
})
.replace(/(\n *)*(\n *)/g, "$2")
.replace(/(`\s*)\+(?=\s*`)/g, "$1\n+")
.replace(/( *)([^\n]*)\n/g, function ($0, space, text)
{
var ret = $0;
if(text.match(/^\{/))
{
indent = space+" ";
indent_fix = "";
}
else if(text.match(/^\}/))
{
indent = space;
indent_fix = "";
}
else
{
if(text.match(/^(case|default)\b/))
ret = indent.substr(0,indent.length-4) + text;
else
ret = indent + indent_fix + text;
if(text.match(/^(if|for|else|var|while)\b/) && !text.match(/\;\s*$/))
indent_fix = " ";
else if(!text.match(/[^\;]\s*$/))
indent_fix = "";
if(text.charAt(0)=='+')
ret = " "+ret;
ret += "\n";
}
return ret;
})
.replace(/\&/g, '&')
.replace(/\</g, '<')
.replace(/\>/g, '>')
.replace(/\x20/g, ' ')
.replace(eval('/\\b('+keywords.join('|')+')\\b/g'),'<font color=blue>$1</font>') // keywords
.replace(eval('/\\b('+objects.join('|')+')\\b/g'),'<font color=red>$1</font>') // objects
.replace(eval('/\\b('+specials.join('|')+')\\b/g'),'<font color=#0099CC>$1</font>') // objects
.replace(/\n/g, '<br>')
.replace(/\'/g, function ($0){return blocks[index++];});
return s;
}
tm_highlight = setTimeout('document.getElementById("oResult").innerHTML = ("<nobr>"+document.getElementById("oTxt").value.formatJS()+"</nobr>");', 1);[/code]
 楼主| 知行 发表于 2011-10-13 12:14 | 显示全部楼层
[code=PHP]<?php

$str = 'dir/upload.image.jpg';

/*方法一*/
$arr = explode('.',$str);
echo end($arr);
echo '<br>';
/*方法二*/
$l = strlen($str);
$prefix = '';
for($i = $l - 1;$i>=0;$i--)
{
if($str{$i} == '.')
{
break;
}
$prefix = $str{$i} . $prefix;

}
echo $prefix;
echo '<br>';
/*方法三*/
echo substr($str,strrpos($str,'.') + 1);[/code]
 楼主| 知行 发表于 2011-10-13 12:19 | 显示全部楼层
论坛自带代码显示效果:
  1. #include <cstdlib>
  2. #include <iostream>
  3. using namespace std;

  4. int Fib(int n);

  5. int main(int argc, char** argv)
  6. {
  7.     int min,max;
  8.         cout<<"请输入数列区间"<<endl;
  9.         cin>>min>>max;
  10.         for(int i=min;i<=max;i++)
  11.         {
  12.                 cout<<Fib(i)<<" ";
  13.         }
  14.         cout<<endl;
  15.     system("pause");
  16.     return 0;
  17. }

  18. int Fib(int n)
  19. {
  20.         if(n<2)
  21.                 return n;
  22.         else
  23.                 return Fib(n-1)+Fib(n-2);
  24. }
复制代码
 楼主| 知行 发表于 2011-10-20 13:59 | 显示全部楼层
代码高亮插件停用

QQ|小黑屋|手机版|知行技术社区 ( 湘ICP备11020288号-1 )

GMT+8, 2020-9-26 12:55 , Processed in 0.021960 second(s), 7 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表