c# - PadRight() isn't padding at all -


i'm trying use string.padright method in c#, it's not doing string.

code:

int strlen = 4 - (data.length % 4); char pad = '='; string datapad = data.padright(strlen, pad); 

the string in question base64 encoded data, , need '=' @ end pad convertfrombase64 work properly.

eyjhbgcioijsuzi1niisimtpzci6ijy5ndzmzjnlzguyotk3zwexmmvhmdrlngfhnjyyowrjzwvhzwzhotaifq 

strlen must greater length of data in order pad it. grant winney points out, padright takes total width of string, , not number of times you'd repeat character @ end of it.

in code below, strlen less or equal 4, lot less length of base 64 encoded string.

int strlen = 4 - (data.length % 4); 

so might want instead:

int strlen = 4 - (data.length % 4) + data.length; 

or just:

string datapad = data.padright(strlen + data.length, pad); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo