How to append text to a JTextArea?

Splitting Text up in python?

  • Basically i need to write code relating to Pseudo-cryptography, in which I am given a message/text and i need to encrypt it. The process includes: Replacing the spaces between words with an “X”. Reversing the text. Padding out the beginning and end of the text with Xs so that the total number of characters is a multiple of four Splitting the text up into blocks of four characters. I have been able to successfully write working code to do the first 3 steps. (See at bottom of question) but i CANNOT and am in dire HELP with the last step. So for example if im given this text: 'heyhowareyou' I need the last step to return: 'heyh owar eyou'. So it needs to be split up all in the same string. Could Anyone please help me with this? Thank you soo MUCH!! Code written so far, that evaluates the first 3 steps: Defining function to encrypt the message. def encrypt(string, block_size): # Padding the begining and end of the text with 'X'. string_list = list(string) string_list.insert(0, 'X') string_list.append('X') string_list = ''.join(string_list) # Reversing the string. string_reversed = string_list[::-1] # Replacing any spaces with 'X'. string_reversed = string_reversed.replace(' ', 'X') Attempt at writing code for fourth step: for index in range(len(string)): string_list_1 = list(string_reversed) string_list_1.insert(4, ' ') string_list_1 = ''.join(string_list_1) return string_list_

  • Answer:

    Maybe something like: (Pseudo-code) index = 0 for eachChar in string if(index > 0 && index%4 = 0) insert a space at the index index++

nameless at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.