Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Truncate String by Byte
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here string chineseWord= "爱上打开链接啊可视对讲阿里卡时间段拉斯建档立卡阿加上了肯定基拉看时间的拉时间到了卡加上了肯定家属楼肯德基拉三季度拉斯建档立卡氨基酸乐凯大街阿斯利康的卢卡斯建档立卡时间的垃圾施蒂利克阿加上了肯定加上了肯定吉拉斯科技的拉丝机打了卡时间了坤道家里肯德基了凯撒奖的拉时间来得快阿家属楼肯德基爱上了空间的拉丝机离开的骄傲沙路口的加上了课建档立卡时间的拉三季度了看见爱上了肯定贾老师肯德基拉卡萨酒店卡视角乐凯大街阿斯利康的基拉看时间的可怜"; Console.WriteLine("Hello, world! Application Start"); var byteGetString = stringToByte(chineseWord,200); var countByte = System.Text.Encoding.UTF8.GetByteCount(byteGetString); Console.WriteLine("Count Byte for byteGetString = " + countByte); var linqCount = stringToByteLinqMethod(chineseWord,200); var countByte2 = System.Text.Encoding.UTF8.GetByteCount(linqCount); Console.WriteLine("Count Byte for stringToByteLinqMethod = " + countByte2); Console.WriteLine("Application Completed"); } static string stringToByte(string input, int maxLength){ if (input != null) { var utf8 = System.Text.Encoding.UTF8; var bytes = utf8.GetBytes(input); input = utf8.GetString(bytes, 0, bytes.Length > maxLength ? maxLength : bytes.Length); } return input; } static string stringToByteLinqMethod(string input, int maxLength){ if (input != null) { input = new String(input.TakeWhile((c, i) => System.Text.Encoding.UTF8.GetByteCount(input.Substring(0, i + 1)) <= maxLength).ToArray()); } return input; } } }
run
|
edit
|
history
|
help
0
/Users/svetlanakanevskaa/Downloads/ACDB.sql
gelman
AdventCode
DN3
parsowanie daty
Uri builder
OneAwayString
asxsdf
My quad calc
User