惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Simon Willison's Weblog
Simon Willison's Weblog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
Last Week in AI
Last Week in AI
月光博客
月光博客
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
U
Unit 42
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
H
Hacker News: Front Page
Recent Announcements
Recent Announcements
C
CXSECURITY Database RSS Feed - CXSecurity.com
Latest news
Latest news
小众软件
小众软件
P
Palo Alto Networks Blog
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest
S
Secure Thoughts
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
O
OpenAI News
S
Securelist
云风的 BLOG
云风的 BLOG
H
Help Net Security
T
Troy Hunt's Blog

博客园 - 三聪

流操作 如何利用.Net内置类,解析未知复杂Json对象 制作等比环切缩缩图 让window.setTimeout等支持带参数方法 利用NewID()生成随机数 创建缩略图 winform给html提供接口 IE下记住文本框的光标位置 ie下取得iframe里面内容 短网址计算 树冲突 截图片 学习Objective-C: 入门教程 asp.net本地和全局资料文件的读取方法 jquery实现点击空白的事件 Asp.net 利用Jquery Ajax传送和接收DataTable 用一个最简单方法解决asp.net页面刷新导致数据的重复提交 SOS"未将对象引用设置到对象的实例" .NET调PHP Web Service的典型例子
C#根据字节数截取字符串
三聪 · 2010-12-21 · via 博客园 - 三聪

        /// <summary>
        
/// 按最大字节数,截取字符串
        
/// </summary>
        
/// <param name="value">要截取的字符串</param>
        
/// <param name="length">最大长度</param>
        
/// <returns></returns>
        private string Intercept(string value, int length)
        {
            
if (value.Length * 2 <= length)
            {
                
return value;
            }
            
string newvalue;
            
for (int i = length / 2; i < value.Length; i++)
            {
                newvalue 
= value.Substring(0, i);
                
if (Encoding.Default.GetByteCount(newvalue) > length)
                {
                    
return value.Substring(0, i - 1);
                }
            }
            
return value;
        }

正确替换多个匹配内容


private void button1_Click(object sender, EventArgs e)
{
    Regex regx 
= new Regex(@"\[image\]", RegexOptions.IgnoreCase);
    
string content = textBox1.Text;
   
    Match m 
= regx.Match(content);
    
while (m.Success)
    {
        content 
= content.Remove(m.Index, m.Value.Length);
        content 
= content.Insert(m.Index, "[picture]");
        m 
= regx.Match(content);

    }

    textBox2.Text 

= content;
}

 方法二:

private void button1_Click(object sender, EventArgs e)
{
    Regex regx 
= new Regex(@"\[image\]", RegexOptions.IgnoreCase);
    
string content = textBox1.Text;
    content
=regx.Replace(content, new MatchEvaluator(DoMatch)); 
    textBox2.Text 
= content;
}
private string DoMatch(Match m)
{
    
return "[picture]";
}

function fmt(s) {

            var value = s.replace(/,/g, "");

            var v = value.replace(/(\d+)(\.\d+)?/, "$1");

            var d = value.replace(/(\d+)(\.\d+)?/, "$2");

            var reg = /\d{4,}\b/;

            while (reg.test(v)) {

                v = v.replace(/(\d{3})\b/, ',$1');

            }

            return v + d; ;

        }