Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Spliting strings

Hi I've been having some problems with my string splitting thingy.

My server is returning me a string (encoded in base64) that I want to transform into an array with the split function but whenever I use the standard javascript string.split("delimiter") my android app crashes, after reading through some documentation I see that there's also a Titanium.Blob.split("delimiter")function but alas that also crashes my app.

server outputs something along these lines:


and these are the ways I tried to make it work

var dresponse = Titanium.Utils.base64decode(this.responseText);
var drespondejs = dresponse.split("###");


var dresponse = Titanium.Utils.base64decode(this.responseText);
var bytes = Titanium.Api.createBlob(dresponse);
var drespondejs = bytes.split("###");

I had various alerts sprawled around the code for debugging purposes and I've narrowed down to the string splitting zone and I would be very thankful if someone could help me.

Thanks in advance

EDIT: I've also made a quick change on the server output so it barfs out something like:


but when I try to eval the result it also crashes, can somebody tell me what am I doing wrong? :(

— asked October 21st 2010 by Rui Morais
  • blob
  • split
  • Hi, I too have problems with standard JavaScript string functions on the android emulator on my mac, a simple split function on a variable fails and throws an exception that split is not recognized. Please note that it works perfectly fine on the iPhone simulator. I am using the 1.4.2 SDK. Please help

    — commented December 27th 2010 by Parijat Naik
  • Hi not sure if this is still causing you problems but I resolved this by declaring a new var and saving the string into it and then calling the split() function. example below:

    var str = dsresponse.toString();

    var drespondejs = str.split("###");

    that seemed to do the trick for me.

    — commented January 30th 2011 by Vineet Belani
  • I know this is old, but it might be worth noting that you can cut out the middle man here.

    Instead of

    var str = dsresponse.toString();
    var drespondejs = str.split("###");

    You can simply put

    var drespondejs = dsresponse.toString().split('###');

    It seems to be the toString() method that allows you to split, as I have tried splitting a regular string which I hard coded into my app and nothing happens. However, I can confirm that this way works.

    — commented December 4th 2013 by Craig Currie

1 Answer

  • Thanks for the answer Vineet…it worked perfectly for me! :)

    — answered April 12th 2012 by Dhairyasheel Shinde
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.