Search Results

Search found 577 results on 24 pages for 'stringbuilder'.

Page 7/24 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • C# MP3 Player using winmm.dll

    - by JoeBeez
    I'm trying to bash together a (very) rough MP3 player during my lunch hour, and so far I've got it to play the files, and I'm working on a way of building a list of filenames to enable random songs, but I think I've just hit a snag. Is there a way of knowing when the currently playing MP3 has finished? An event or some such? As it stands I don't think I'd be able to have playlists etc unless this was possible due to it stopping after every playback. I've attatched the whole source below, feel free to pick it apart and give me any feedback you may have, cheers. using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace X { public partial class Form1 : Form { List<string> Names = new List<string>(); StreamReader reader = File.OpenText(@"C:\X.txt"); string line; OpenFileDialog ofd = new OpenFileDialog(); StringBuilder buffer = new StringBuilder(128); string CommandString; [DllImport("winmm.dll")] private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback); public Form1() { InitializeComponent(); while ((line = reader.ReadLine()) != null) { if (line.Trim() != "") { Names.Add(line.Trim()); } } } private void btnplay_Click(object sender, EventArgs e) { if (ofd.FileName == "") { if (ofd.ShowDialog() == DialogResult.OK) { ofd.Filter = "MP3 Files|*.mp3"; CommandString = "open " + "\"" + ofd.FileName + "\"" + " type MPEGVideo alias Mp3File"; mciSendString(CommandString, null, 0, 0); CommandString = "play Mp3File"; mciSendString(CommandString, null, 0, 0); } } else { CommandString = "play Mp3File"; mciSendString(CommandString, null, 0, 0); } } private void btnpause_Click(object sender, EventArgs e) { CommandString = "pause mp3file"; mciSendString(CommandString, null, 0, 0); } private void btnbrowse_Click(object sender, EventArgs e) { ofd.Filter = "Mp3 files |*.mp3"; if (ofd.ShowDialog() == DialogResult.OK) { txtpath.Text = ofd.FileName; CommandString = "close Mp3File"; mciSendString(CommandString, null, 0, 0); CommandString = "open " + "\"" + ofd.FileName + "\"" + " type MPEGVideo alias Mp3File"; mciSendString(CommandString, null, 0, 0); } } } }

    Read the article

  • Stored Procedure call with parameters in ASP.NET MVC

    - by cc0
    I have a working controller for another stored procedure in the database, but I am trying to test another. When I request the URL; http://host.com/Map?minLat=0&maxLat=50&minLng=0&maxLng=50 I get the following error message, which is understandable but I can't seem to find out why it occurs; Procedure or function 'esp_GetPlacesWithinGeoSpan' expects parameter '@MinLat', which was not supplied. This is the code I am using. using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; using System.Data; using System.Text; using System.Data.SqlClient; namespace prototype.Controllers { public class MapController : Controller { //Initial variable definitions //Array with chars to be used with the Trim() methods char[] lastComma = { ',' }; //Minimum and maximum lat/longs for queries float _minLat; float _maxLat; float _minLng; float _maxLng; //Creates stringbuilder object to store SQL results StringBuilder json = new StringBuilder(); //Defines which SQL-server to connect to, which database, and which user SqlConnection con = new SqlConnection(...connection string here...); // // HTTP-GET: /Map/ public string CallProcedure_getPlaces(float minLat, float maxLat, float minLng, float maxLng) { con.Open(); using (SqlCommand cmd = new SqlCommand("esp_GetPlacesWithinGeoSpan", con)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@MinLat", _minLat); cmd.Parameters.AddWithValue("@MaxLat", _maxLat); cmd.Parameters.AddWithValue("@MinLng", _minLng); cmd.Parameters.AddWithValue("@MaxLng", _maxLng); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { json.AppendFormat("\"{0}\":{{\"c\":{1},\"f\":{2}}},", reader["PlaceID"], reader["PlaceName"], reader["SquareID"]); } } con.Close(); } return "{" + json.ToString().TrimEnd(lastComma) + "}"; } //http://host.com/Map?minLat=0&maxLat=50&minLng=0&maxLng=50 public ActionResult Index(float minLat, float maxLat, float minLng, float maxLng) { _minLat = minLat; _maxLat = maxLat; _minLng = minLng; _maxLng = maxLng; return Content(CallProcedure_getPlaces(_minLat, _maxLat, _minLng, _maxLng)); } } } Any help on resolving this problem would be greatly appreciated.

    Read the article

  • How do I parse JSON from a Java HTTPResponse?

    - by Joe Ludwig
    I have an HttpResponse object for a web request I just made. The response is in the JSON format, so I need to parse it. I can do it in an absurdly complex way, but it seems like there must be a better way. Is this really the best I can do? HttpResponse response; // some response object Reader in = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); StringBuilder builder= new StringBuilder(); char[] buf = new char[1000]; int l = 0; while (l >= 0) { builder.append(buf, 0, l); l = in.read(buf); } JSONTokener tokener = new JSONTokener( builder.toString() ); JSONArray finalResult = new JSONArray( tokener ); I'm on Android if that makes any difference.

    Read the article

  • Problem showing modelstate errors while using RenderPartialToString

    - by Martin
    Im using the following code: public string RenderPartialToString(ControllerContext context, string partialViewName, ViewDataDictionary viewData, TempDataDictionary tempData) { ViewEngineResult result = ViewEngines.Engines.FindPartialView(context, partialViewName); if (result.View != null) { StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter output = new HtmlTextWriter(sw)) { ViewContext viewContext = new ViewContext(context, result.View, viewData, tempData, output); result.View.Render(viewContext, output); } } return sb.ToString(); } return String.Empty; } To return a partial view and a form through JSON. It works as it should, but as soon as I get modelstate errors my ValidationSummary does not show. The JSON only return the default form but it does not highlight the validation errors or show the validation summary. Am I missing something? This is how I call the RenderPartialToString: string partialView = RenderPartialToString(this.ControllerContext, "~/Areas/User/Views/Account/ChangeAccountDetails.ascx", new ViewDataDictionary(avd), new TempDataDictionary());

    Read the article

  • There is insufficient system memory to run this query when creating temporary table

    - by phenevo
    StringBuilder query = new StringBuilder(); query.Append("CREATE TABLE #Codes (Code nvarchar(100) collate database_default ) "); query.Append("Insert into #Codes (Code) "); int lengthOfCodesArray = targetCodes.Length; for (int index = 0; index < lengthOfCodesArray; index++) { string targetCode = targetCodes[index]; query.Append("Select N'" + targetCode + "' "); if (index != lengthOfCodesArray - 1) { query.Append("Union All "); } } query.Append("drop table #Codes "); on: cmd.ExecuteReader() I get There is insufficient system memory to run this query when creating temporary table But weird thing is that, when I have 25k codes is ok, when 5k I get this error. Initial size is 262 MB. Lengt of each code is average 15.

    Read the article

  • JavaScriptSerializer with custom Type

    - by balint
    Hi, I have a function with a List return type. I'm using this in a JSON-enabled WebService like: [WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Product> GetProducts(string dummy) /* without a parameter, it will not go through */ { return new x.GetProducts(); } this returns: {"d":[{"__type":"Product","Id":"2316","Name":"Big Something ","Price":"3000","Quantity":"5"}]} I need to use this code in a simple aspx file too, so I created a JavaScriptSerializer: JavaScriptSerializer js = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); List<Product> products = base.GetProducts(); js.RegisterConverters(new JavaScriptConverter[] { new ProductConverter() }); js.Serialize(products, sb); string _jsonShopbasket = sb.ToString(); but it returns without a type: [{"Id":"2316","Name":"Big One ","Price":"3000","Quantity":"5"}] Does anyone have any clue how to get the second Serialization work like the first? Thanks!

    Read the article

  • MD5 in Object-C and C#

    - by user360161
    Hi, I have a method written in c# to get md5: public static string encryptPasswordWithMd5(string password) { MD5 md5Hasher = MD5.Create(); byte[] data = md5Hasher.ComputeHash(Encoding.Unicode.GetBytes(password)); StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.Length; i++) sb.Append(data[i].ToString("x2")); return sb.ToString(); } now I need to implement the same function using objective-c, how to do it...

    Read the article

  • How to Generate Server-Side tags dynamiclly

    - by Nasser Hajloo
    I have an ASP.net page which contains some controls. I generate this controls by code, [Actually I have a method which uses a stringBuilder and add Serverside tag as flat string on it] My page shows the content correctly but unfortunately my controls became like a Client-side control For example I had a LoginView on my generated code which dosen't work, and also I had read some string from LocalResources which dosen't appear on the page What Should I do to make my generating method correct here is the code protected string CreateSubSystem(string id, string roles, string AnonymousTemplateClass, string href, string rolesContentTemplateClass, string LoggedInTemplateClass) { StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"SubSystemIconPlacement\" id=\""); sb.Append(id); sb.Append("\"><asp:LoginView runat=\"server\" ID=\""); sb.Append(id); sb.Append("\"><AnonymousTemplate><div class=\""); sb.Append(AnonymousTemplateClass); sb.Append("\"></div><asp:Label ID=\"lblDisabled"); sb.Append(id); sb.Append("\" runat=\"server\" SkinID=\"OneColLabel\" meta:resourcekey=\"lbl"); sb.Append(id); sb.Append("\" /></AnonymousTemplate><RoleGroups><asp:RoleGroup Roles=\""); sb.Append(roles); sb.Append("\"><ContentTemplate><a class=\"ImageLink\" href=\""); sb.Append(href); sb.Append("\"><div class=\""); sb.Append(rolesContentTemplateClass); sb.Append("\"></div></a><asp:HyperLink runat=\"server\" CssClass=\"SubSystemText\" ID=\"lnk"); sb.Append(id); sb.Append(" NavigateUrl=\"~/"); sb.Append(href); sb.Append(" \" meta:resourcekey=\"lbl"); sb.Append(id); sb.Append("\" /></ContentTemplate></asp:RoleGroup></RoleGroups><LoggedInTemplate><div class=\""); sb.Append(LoggedInTemplateClass); sb.Append("\"></div><asp:Label runat=\"server\" SkinID=\"OneColLabel\" ID=\"lblDisabledLoggedIn"); sb.Append(id); sb.Append("\" meta:resourcekey=\"lbl"); sb.Append(id); sb.Append("\" /></LoggedInTemplate></asp:LoginView>"); sb.Append("</div>"); return sb.ToString(); } I also use this method on page_PreRender event

    Read the article

  • Best way to create SEO friendly URI string

    - by Mat Banik
    The method below allows only "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-" chars in URI strings. What better way is there to make nice SEO URI string? import org.apache.commons.lang.StringUtils; public static String safeChar(String input) { input = input.trim(); input = StringUtils.replace(input, " -", "-"); input = StringUtils.replace(input, "- ", "-"); input = StringUtils.replace(input, " - ", "-"); input = StringUtils.replaceChars(input, '\'', '-'); input = StringUtils.replaceChars(input, ' ', '-'); char[] allowed = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-".toCharArray(); char[] charArray = input.toCharArray(); StringBuilder result = new StringBuilder(); for (char c : charArray) { for (char a : allowed) { if (c == a) result.append(a); } } return result.toString(); }

    Read the article

  • OutOfMemoryError what to increase and how?

    - by Pentium10
    I have a really long collection with 10k items, and when running a toString() on the object it crashes. I need to use this output somehow. 05-21 12:59:44.586: ERROR/dalvikvm-heap(6415): Out of memory on a 847610-byte allocation. 05-21 12:59:44.636: ERROR/dalvikvm(6415): Out of memory: Heap Size=15559KB, Allocated=12932KB, Bitmap Size=613KB 05-21 12:59:44.636: ERROR/AndroidRuntime(6415): Uncaught handler: thread main exiting due to uncaught exception 05-21 12:59:44.636: ERROR/AndroidRuntime(6415): java.lang.OutOfMemoryError 05-21 12:59:44.636: ERROR/AndroidRuntime(6415): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97) 05-21 12:59:44.636: ERROR/AndroidRuntime(6415): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:155) 05-21 12:59:44.636: ERROR/AndroidRuntime(6415): at java.lang.StringBuilder.append(StringBuilder.java:202) 05-21 12:59:44.636: ERROR/AndroidRuntime(6415): at java.util.AbstractCollection.toString(AbstractCollection.java:384) I need step by step guide how to increase the heap for and Android application. I don't run the command line.

    Read the article

  • Looking for an HQL builder (Hibernate Query Language)

    - by Sébastien RoccaSerra
    I'm looking for a builder for HQL in Java. I want to get rid of things like: StringBuilder builder = new StringBuilder() .append("select stock from ") .append( Stock.class.getName() ) .append( " as stock where stock.id = ") .append( id ); I'd rather have something like: HqlBuilder builder = new HqlBuilder() .select( "stock" ) .from( Stock.class.getName() ).as( "stock" ) .where( "stock.id" ).equals( id ); I googled a bit, and I couldn't find one. I wrote a quick & dumb HqlBuilder that suits my needs for now, but I'd love to find one that has more users and tests than me alone. Note: I'd like to be able to do things like this and more, which I failed to do with the Criteria API: select stock from com.something.Stock as stock, com.something.Bonus as bonus where stock.someValue = bonus.id ie. select all stocks whose property someValue points to any bonus from the Bonus table. Thanks!

    Read the article

  • NOT IN statement for Visual Studio's Query Builder for TableAdapter

    - by Fabiano
    Hi I want to realize a query with the Visual Studio 2008 build in Query Builder for a TableAdapter similar like following (MSSQL 2008): select * from [MyDB].[dbo].[MyView] where UNIQUE_ID NOT IN ('MyUniqueID1','MyUniqueID2') How do I have to set the Filter in my query in order to call it with the myTableAdapter.GetDataExceptUniqueIds(...) function? I tried to set the filter to NOT IN (@ids) and called it with string[] uniqueIds = ...; myTableAdapter.GetDataExceptUniqueIds(String.Join("','", uniqueIds)); and with StringBuilder sb = new StringBuilder("'"); sb.Append(String.Join("','", uniqueIds)); sb.Append("'"); return myTableAdapter.GetDataExceptUniqueIds(sb.ToString()); but both failed

    Read the article

  • Why isn't this MVC Html Helper extension method working?

    - by Blankman
    My base controller looks like: public abstract MyBaseMasterController<TMasterViewModel> : Controller { } public MyMasterController: MyBaseMasterController<SomeThingModel> { } Extension method: public static string DoSomething(this HtmlHelper htmlHelper) { StringBuilder sb = new StringBuilder(); sb.Append("var cnwglobals = {"); var controller = htmlHelper.ViewContext.Controller as MyMasterController; if (controller == null) { } return sb.ToString(); } In my view I do: <% Html.Dosomething(); %> I get an error: CS1061: 'System.Web.Mvc.HtmlHelper<Blah.Models.ViewModelForMasterWrapper<Blah.Models.MasterViewModel>>' does not contain a definition for 'DoSomething' and no extension method 'DoSomething' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Blah.Models.ViewModelForMasterWrapper<Blah.Models.MasterViewModel>>' could be found (are you missing a using directive or an assembly reference?)

    Read the article

  • Make CSV from list of string in LINQ

    - by CmdrTallen
    Hi I would like to take a list collection and generate a single csv line. So take this; List<string> MakeStrings() { List<string> results = new List<string>(); results.add("Bob"); results.add("Nancy"); results.add("Joe"); results.add("Jack"); } string ContactStringsTogether(List<string> parts) { StringBuilder sb = new StringBuilder(); foreach (string part in parts) { if (sb.Length > 0) sb.Append(", "); sb.Append(part); } return sb.ToString(); } This returns "Bob,Nancy,Joe,Jack" Looking for help on the LINQ to do this in a single statement. Thanks!

    Read the article

  • Not getting correct time from UniversalDateTime

    - by Nakul Chaudhary
    I send a vcal through mail in web application with convert datetime to universal datetime. If i run web application locally (local sevser in India) i get correct time in my vcal. But run appication live (server in US) then not get corret time with a difference of 1 and half hour.Please suggest me. code : Dim result As StringBuilder = New StringBuilder() result.AppendFormat("BEGIN:VCALENDAR{0}", System.Environment.NewLine) result.AppendFormat("BEGIN:VEVENT{0}", System.Environment.NewLine) result.AppendFormat("SUMMARY:{0}{1}", subject, System.Environment.NewLine) result.AppendFormat("LOCATION:{0}{1}", location, System.Environment.NewLine) result.AppendFormat("DTSTART:{0}{1}", startDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"), System.Environment.NewLine) result.AppendFormat("DTEND:{0}{1}", endDate.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"), System.Environment.NewLine) result.AppendFormat("DTSTAMP:{0}{1}", DateTime.Now.ToUniversalTime().ToString("yyyyMMdd\THHmmss\Z"), System.Environment.NewLine) result.AppendFormat("DESCRIPTION:{0}{1}", description, System.Environment.NewLine) result.AppendFormat("END:VEVENT{0}", System.Environment.NewLine) result.AppendFormat("END:VCALENDAR{0}", System.Environment.NewLine) Return result.ToString()

    Read the article

  • Detect Client Computer name when an RDP session is open

    - by Ubiquitous Che
    Hey all, My manager has pointed out to me a few nifty things that one of our accounting applications can do because it can load different settings based on the machine name of the host and the machine name of the client when the package is opened in an RDP session. We want to provide similar functionality in one of my company's applications. I've found out on this site how to detect if I'm in an RDP session, but I'm having trouble finding information anywhere on how to detect the name of the client computer. Any pointers in the right direction would be great. I'm coding in C# for .NET 3.5 EDIT The sample code I cobbled together from the advice below - it should be enough for anyone who has a use for the WTSQuerySessionInformation to get a feel for what's going on. Note that this isn't necessarily the best way of doing it - just a starting point that I've found useful. When I run this locally, I get boring, expected answers. When I run it on our local office server in an RDP session, I see my own computer name in the WTSClientName property. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace TerminalServicesTest { class Program { const int WTS_CURRENT_SESSION = -1; static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero; static void Main(string[] args) { StringBuilder sb = new StringBuilder(); uint byteCount; foreach (WTS_INFO_CLASS item in Enum.GetValues(typeof(WTS_INFO_CLASS))) { Program.WTSQuerySessionInformation( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, item, out sb, out byteCount); Console.WriteLine("{0}({1}): {2}", item.ToString(), byteCount, sb); } Console.WriteLine(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } [DllImport("Wtsapi32.dll")] public static extern bool WTSQuerySessionInformation( IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out StringBuilder ppBuffer, out uint pBytesReturned); } enum WTS_INFO_CLASS { WTSInitialProgram = 0, WTSApplicationName = 1, WTSWorkingDirectory = 2, WTSOEMId = 3, WTSSessionId = 4, WTSUserName = 5, WTSWinStationName = 6, WTSDomainName = 7, WTSConnectState = 8, WTSClientBuildNumber = 9, WTSClientName = 10, WTSClientDirectory = 11, WTSClientProductId = 12, WTSClientHardwareId = 13, WTSClientAddress = 14, WTSClientDisplay = 15, WTSClientProtocolType = 16, WTSIdleTime = 17, WTSLogonTime = 18, WTSIncomingBytes = 19, WTSOutgoingBytes = 20, WTSIncomingFrames = 21, WTSOutgoingFrames = 22, WTSClientInfo = 23, WTSSessionInfo = 24, WTSSessionInfoEx = 25, WTSConfigInfo = 26, WTSValidationInfo = 27, WTSSessionAddressV4 = 28, WTSIsRemoteSession = 29 } }

    Read the article

  • Is there a way to add name/value functionality to jquery autocomplete for .net?

    - by Mark Kadlec
    I've recently added the JQuery autocomplete plug in and have a textbox that autocompletes a list of employees. It works great and I commend the authors of the plugin. I think the textbox would be MUCH more useful though, when upon selecting, we can extract the StaffID (Ie. retreive the value of the selection). My code is below and you can see that I am simply adding the staff names, would be nice to associate IDs. Does anyone know of any way to do this? My JQuery: $(document).ready(function() { $("#txtStaff").autocomplete('autocompletetagdata.aspx'); }); My ASPX page: protected void Page_Load(object sender, EventArgs e) { StaffViewListClass staffList = StaffViewListClass.GetStaff(); StringBuilder sb = new StringBuilder(); foreach (StaffViewClass staff in staffList) { sb.Append(staff.FullName).Append("\n"); } Response.Write(sb.ToString()); }

    Read the article

  • C# streamreader, delimiter problem.

    - by Mike
    What I have is a txt file that is huge, 60MB. I need to read each line and produce a file, split based on a delimiter. I'm having no issue reading the file or producing the file, my complication comes from the delimiter, it can't see the delimiter. If anybody could offer a suggestion on how to read that delimiter I would be so grateful. delimiter = Ç public void file1() { string betaFilePath = @"C:\dtable.txt"; StringBuilder sb = new StringBuilder(); using (FileStream fs = new FileStream(betaFilePath, FileMode.Open)) using (StreamReader rdr = new StreamReader(fs)) { while (!rdr.EndOfStream) { string[] betaFileLine = rdr.ReadLine().Split('Ç'); { sb.AppendLine(betaFileLine[0] + "ç" + betaFileLine[1] + betaFileLine[2] + "ç" + betaFileLine[3] + "ç" + betaFileLine[4] + "ç" + betaFileLine[5] + "ç" + betaFileLine[6] + "ç" + betaFileLine[7] + "ç" + betaFileLine[8] + "ç" + betaFileLine[9] + "ç" + betaFileLine[10] + "ç"); } } } using (FileStream fs = new FileStream(@"C:\testarea\load1.txt", FileMode.Create)) using (StreamWriter writer = new StreamWriter(fs)) { writer.Write(sb.ToString()); } }

    Read the article

  • Is there a Java API for creating a XHTML document?

    - by Bedwyr Humphreys
    I want to provide a simple XHTML representation of each of the resources in a REST web service. At the moment i'm using a StringBuilder to generate these which is both tedious and error prone. I don't see these changing after I publish the service but the process of coding each is a bit painful. Is there a XHTML document writer api? Should I just use an XML writer? Which one? Should I just roll my own basic HTML document class - doctype is the same each time, i just need to set the title, metatags and body content, most of which (but not all content) is already in HTML for the GETs. Or should I just use StringBuilder and stop whining? ;) Thanks.

    Read the article

  • Text Decoding Problem

    - by Jason Miesionczek
    So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) { StringBuilder sb = new StringBuilder(); MatchCollection matches = Regex.Matches(inputText.Text, @"=\?(?<encoding>[\S]+)\?.\?(?<data>[\S]+[=]*)\?="); foreach (Match m in matches) { string encoding = m.Groups["encoding"].Value; string data = m.Groups["data"].Value; Encoding enc = Encoding.GetEncoding(encoding.ToLower()); if (enc == Encoding.UTF8) { byte[] d = Convert.FromBase64String(data); sb.Append(Encoding.ASCII.GetString(d)); } else { byte[] bytes = Encoding.Default.GetBytes(data); string decoded = enc.GetString(bytes); sb.Append(decoded); } } return sb.ToString(); } The result is the same as the data extracted from the input string. What am i doing wrong that this text is not getting decoded properly?

    Read the article

  • How use asp.net get video duration

    - by mhmt
    using Microsoft.DirectX.AudioVideoPlayback; Video vvideo = new Video(FileUpload.FileName.ToString()); StringBuilder sb = new StringBuilder(); sb.Append(duration.toString()); error message; “Installed an access attempt was made to the application domain.” “vvideo” instance is created error msj :// But down found cods I found a working code in c #. but asp.net does not work string file1 = "c://ds.mpeg" IMediaPosition m_objMediaPosition = null; FilgraphManager m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(filename); m_objMediaPosition = m_objFilterGraph as IMediaPosition; int s = (int)m_objMediaPosition.Duration; int h = s / 3600; int m = (s - (h * 3600)) / 60; s = s - (h * 3600 + m * 60); I DON'T TAKE VIDEO DURATION BOYS :/

    Read the article

  • String codification to Twitter

    - by Miguel Ribeiro
    I'm developing a program that sends tweets. I have this piece of code: StringBuilder sb = new StringBuilder("Recomendo "); sb.append(lblName.getText()); sb.append(" no canal "+lblCanal.getText()); sb.append(" no dia "+date[2]+"/"+date[1]+"/"+date[0]); sb.append(" às "+time[0]+"h"+time[1]); byte[] defaultStrBytes = sb.toString().getBytes("ISO-8859-1"); String encodedString = new String(defaultStrBytes, "UTF-8"); But When I send it to tweet I get the "?" symbol or other strage characters because of the accents like "à" . I've also tried with only String encodedString = new String(sb.toString().getBytes(), "UTF-8"); //also tried with ISO-8859-1 but the problem remains...

    Read the article

  • running Echo from Java

    - by ripper234
    I'm trying out the Runtime.exec() method to run a command line process. I wrote this sample code, which runs without problems but doesn't produce a file at c:\tmp.txt. String cmdLine = "echo foo > c:\\tmp.txt"; Runtime rt = Runtime.getRuntime(); Process pr = rt.exec(cmdLine); BufferedReader input = new BufferedReader( new InputStreamReader(pr.getInputStream())); String line; StringBuilder output = new StringBuilder(); while ((line = input.readLine()) != null) { output.append(line); } int exitVal = pr.waitFor(); logger.info(String.format("Ran command '%s', got exit code %d, output:\n%s", cmdLine, exitVal, output)); The output is INFO 21-04 20:02:03,024 - Ran command 'echo foo c:\tmp.txt', got exit code 0, output: foo c:\tmp.txt

    Read the article

  • java: speed up reading foreign characters

    - by Yang
    My current code needs to read foreign characters from the web, currently my solution works but it is very slow, since it read char by char using InputStreamReader. Is there anyway to speed it up and also get the job done? // Pull content stream from response HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); StringBuilder contents = new StringBuilder(); int ch; InputStreamReader isr = new InputStreamReader(inputStream, "gb2312"); // FileInputStream file = new InputStream(is); while( (ch = isr.read()) != -1) contents.append((char)ch); String encode = isr.getEncoding(); return contents.toString();

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >