.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to count number of bytes in string for utf-8 encoding

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application

How to find number of bytes in string in utf-8 encoding ?

str.Length returns number of characters but in utf-8 encoding some characters occupy more than 1 byte ? 

View Complete Post

More Related Resource Links

Encoding.ASCII.GetString(bytes) return string with not expected

Example   byte[] bytes = {  0x36,0x92,0x30,0x94}; string rs=  Encoding.ASCII.GetString(bytes) ; //result rs = ?60?   Is Wrong Result; Result Right is     '60". So this function should fix to properly decode two symbols ' and " Code ASCII ' is 0x92,Code ACII for " is  0x94

encoding/decoding a string to/from bitmap


I have two methods:

Encode - takes a string, converts it to array of bytes, uses bytes to specify colors, creates a color and sets a pixel based on bytes

Decode - takes a pixel, retrieves color (R,G,B) bytes and converts them to characters, that produces a string which was previously encoded

I'm using two for loops (img height/width) to specify position and access pixels

The issue is that once display (Control Panel\Appearance and Personalization\Display) changes to anything other then "Smaller - 100%",
bytes have different values during decoding, thus different string is produced (corrupted).

If the setting is set to "Smaller - 100%" the results are normal.

What can I do to avoid that problem?

Thanks in advance

Cannot count number of checked items using jQuery

Hello,Using Microsoft built-in jquery files, when counting numbers of checked checkbox, the jquery-1.4.2.min.js cannot count the correct result ,however, the version jquery-1.3.2.min.js gives out the correct one, why?            $("#check").click(function () {                var nameSports = new Array();                var i = 0;                $('input[name=selector]:checked').each(function () {                    nameSports[i] = jQuery(this).val();                    i += 1;                });                if (loopCounter != 0) {                    alert(i);                }  

how to count the occurence of a perticular string inside a string.

I have 1000 rows in a table with 20 columns. One of the column has Resource wjich is character data type and values can be eithe General Information, Success Stories and which can be separated by commas and can be repeated multiple times in a row. I want to find out  how many times Success Stories repeats in a perticular row Eg:  In the below row  string Sucess Stories repeats 2 times. So I should get the count as 2.  General Information,Success Stories,White Papers, Sucess Stories Can anyone please help to write sql for the above logic.   Thanks  

Count of number of times the document is downloaded from document library

Hi All, I am working on sharepoint 2007.  My requirement is: I need to take the count of number of times the document is downloaded from document library. I used log report which doesn't solved my purpose. Any Idea how can we acheive this ?   Regards

How to count number of characters in a textbox?

On my current form I have it validating a Canadian Postal Address (xxx xxx). The space is optional but if the user does not use a space, then once the validation passes it will insert one. How can I count the first 3 characters of the textbox, insert a space, then add the rest of the characters?Thank you

Extract number from string


How i extract 0 from " flag=0" OR "flag = 0".

These are string value.

How to count characters in a string, by type


Say I have a string in a text box like


I wish to count the number of pipes or '|'.

How can I do this with js ???

count number of files after uploading


Hello, im hope i can make sense to this post cause i dont have an idea where to begin :-) I have some files upload code so the user can upload files to the server (it can be 1 or 5 or 20 files). the code is working fine, and the files uploading to the folder on the server. The problem is, that after the files uploads i need to display to the user some textboxes to every file (like: number of copies, if its color or b/w, the print size etc). is there some way, after the files is uploaded, to show the user the name of the files and for each file name to display some textboxes (like: to count the number of files and then display the names and few same textboxes for each file), thanks

Count the number of users per web page


Hello everyone,

I have a website that has 10 aspx pages in it, and I'm trying to count how many users are on any one page at a time, and display that number on the web page.  I have set it up to use an Application object ("TotalViewers"), and initialize it to 0 in the Application_Start event handler of the global.asax file.  My reasoning (probably way off base) is to increment the count on each page load, and then decrement the count on each page unload.  The increment part works ok, but when I add the code in the page unload event handler to decrement, it seems that Unload happens before the Page is presented to the client, so the  value always stays the same (adds one in page load, subtracts one in page unload).

How else  can I track number of users on each page?  (simply, becuase I am still a beginner).  I have already done some google searching and haven't come up with anything useful. 

All my pages are being navigated via a TreeView control.

Thank you,





Pass index number and find the char in a string?


How do i find the charactors in teh first index and the last index number of a string? 


Count gives me the same answer regardless of the number of rows


I always get a result of zero from the following code sequence even as the row count changes and I just do not see what the error in my syntax is.




supercount As Integer

supercount = 0


Dim sqlkit As String

sqlkit =

help encoding a string like this: The%20Best%20Place%20in%20Vancouver


how do I convert a string like this: "The Best Place in Vancouver " to this -> The%20Best%20Place%20in%20Vancouver





Count the number of months since start date Options

I have a Measure.TransactionValue and also a Date.Month Dim and a 
Subscriber Dim 

I want to do a Count of months since first transaction date by 

Subscriber | Month | Measure.TransactionValue | 
1 | 201002 | 0 | 0 
1 | 201003 | 100 | 1 
1 | 201004 | 200 | 2 
1 | 201005 | 300 | 3 
1 | 201006 | 0 | 4 
1 | 201007 | 50 5

Make sense?

Any help would be greatly appreciated. 

count number of columns in group



I need to count number of columns in group -

I have a matrix with SUM in the date area.

I have a group column (lats say 'city') and under it my columns (lats say 'street name');

Under each 'street name' I have cell with SUM function.

The problem is:

When The main group (city) is not expand I get the sum of all cities and what I want to get is an average .

So what I thought of was to divide that number in the number of streets under each city group.

How can I get that number?


String.Format rounding down floating point number


Hi, I'm having an issue with String.Format, can somebody tell me if it's something I'm doing.


I'm using C# 2.0 I have code which looks a little bit like this:


Code Snippet

string result;

float floatToConvert = 10780503.000000f;


result = String.Format("{0:0,0}",floatToConvert);



Now I would expect result to have a value of "10,780,503" after this line of code, but it doesn't it has a value of "10,780,500"...


If however I do this:


Code Snippet

string result;

float floatToConvert = 10780503.000000f;

Count the number of times a SP ran in the past?


I am trying to see how many times a set of 50 sp's ran on my prod server. The idea is to remove the ones not being used anymore and clean the unused sps. My environment is Sql Server 2005 sp3

I did a basic search online and found out that sys.dm_exec_query_stats does a good job in giving the cout but only if the cache has not been flushed out. How do i know when was the last time the cache was flushed out in my sql server? Also what do they mean by cache being flushed out?

Is there a better way to capture all my sp execution counts on SQL Server 2005 other than running a server side trace?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend