This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
L337(0D3R


Newbie


Joined: 26 May 2010
Posts: 1

Posted: 26 May 2010 04:44:28 pm    Post subject:

I want to know how to edit a part of a large string. An example is below.

I want to turn "1 2 3 0 0 0 7i8i9i1 2 3 4i0 0 0 8i9i1 2 3 0 5i0 7i0 9i1 2 3 0 0 6i7i8i0 "
into "1 2 3 0 0 0 7i8i9i1 2 3 4i0 0 0 8i9i0 0 0 0 0 0 0 0 0 1 2 3 0 0 6i7i8i0 ".
Back to top
thepenguin77


Advanced Newbie


Joined: 17 Jul 2009
Posts: 72

Posted: 26 May 2010 08:00:10 pm    Post subject:

The best I can think of is to just use sub( take the parts that you want, of course it all depends on how much you know about the string.


Code:

"1 2 3 0 0 0 7i8i9i1 2 3 4i0 0 0 8i9i1 2 3 0 5i0 7i0 9i1 2 3 0 0 6i7i8i0
sub(ans,1,36)+"0 0 0 0 0 0 0 0 0 "+sub(ans,55,17


You can replace whatever of those numbers in the sub('s with variables if they are going to change.

I don't know if you need to use a string or not, but lists are much easier. You can access each variable with L1(1), L1(2) and so on.


Last edited by Guest on 26 May 2010 08:01:52 pm; edited 1 time in total
Back to top
Deep Thought


Advanced Newbie


Joined: 09 Jun 2009
Posts: 59

Posted: 27 May 2010 04:19:51 pm    Post subject:

thepenguin77 wrote:

The best I can think of is to just use sub( take the parts that you want, of course it all depends on how much you know about the string.


Code:

"1 2 3 0 0 0 7i8i9i1 2 3 4i0 0 0 8i9i1 2 3 0 5i0 7i0 9i1 2 3 0 0 6i7i8i0
sub(ans,1,36)+"0 0 0 0 0 0 0 0 0 "+sub(ans,55,17


You can replace whatever of those numbers in the sub('s with variables if they are going to change.

I don't know if you need to use a string or not, but lists are much easier. You can access each variable with L1(1), L1(2) and so on.


There have been many instances where I've needed to use the string operations you mentioned, and sometimes, there's no way to know what the string was in the first place (e.g., when I want to replace all instances of one character in the string with a different character). I'd still use the sub( command, as thepenguin77 said, but using a variable and length( as parts of the second and third arguments. For example, if you need to replace the character of Str1 at place A with a "0":


Code:

sub(Str1,1,A-1)+"0"+sub(Str1,A+1, length(Str1)-A→Str1
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement