How do I delete a character in 6502 basic? Like reverse print...
Would there be a way to channel the del key code into a program? I have tried looking at the reference but there is nothing there for a command.
As OldBoyCoder suggests, it can be done - but the character depends on the platform.
10 PRINT "AB";
20 PRINT "C"
Output on Commodore PET or Apple II:
ABC
For Commodore PET add:
15 PRINT CHR$(20);
Output:
AC
On the Apple II you'd need to use 8 instead of 20 because the I/O firmware is different.
You can also use the string manipulation commands, such as LEFT$, RIGHT$ and MID$, here's an untested example from memory (for the Commodore PET and other Commodore 8-bit machines, probably also works on other variants of BASIC):
0 A$="ABC"
1 PRINT LEFT$(A$,2): REM PRINTS AB
2 PRINT RIGHT$(A$,2): REM PRINTS BC
3 PRINT MID$(A$,2,1): REM PRINTS B
Otherwise, you can over-write characters as long as you know where they are located on the screen.
0 D$=CHR$(17): REM CURSOR DOWN
1 U$=CHR$(145): REM CURSOR UP
2 R$=CHR$(29): REM CURSOR RIGHT
3 L$=CHR$(157): REM CURSOR LEFT
4 PRINT "ABC";L$;" "
I'm using CHR$ codes here for clarity. If you open a string with a double-quote, you can press the UP/DOWN and LEFT/RIGHT keys which will show inversed characters. Printing these inversed characters will do the same as moving the cursor around with the cursor keys.
Related
I want to transform this following text in a single line from
[12.2,3.3 ,8.1 ,9., 12.4]
to
5
12.2
3.3
8.1
9.
12.4
or from
[def, abc , ghi ]
into
3
def
abc
ghi
So, essentially, removing [ and ], breaking elements based on , and remove leading or trailing spaces, and then put the number of elements as the first line (5 in the first example and 3 in the second) and each element in the following lines.
How to write a command to do this fast in vim?
Steps
1.Strip spaces in the list:
:s/ //g
2.Add number of elements to the start:
:s/\v\[(([^,]+)*[^\]]+)\]/\=len(split(submatch(1), ',')).','.submatch(1)/
3.Replace , with \r:
:s/,/\r/g
Results
After first step:
[12.2,3.3,8.1,9.,12.4]
After second step:
5,12.2,3.3,8.1,9.,12.4
After last step:
5
12.2
3.3
8.1
9.
12.4
If you are ok with python(installed in your os and activated in vim) you can:
edit the text to:
a=[your list];print(len(a));
for x in a:print(x)
enter visual mode and select all the text
just type :!python and it should transform your list to the desired shape, replacing the original
P. S.: the string need to be quoted in order for this to work
I'm trying to find a regex (that will work in node.js) to remove the Fahrenheit and Celsius letters and replace them with " degrees" from the below weather forecast string.
"Clear skies. Low 46F. NNW winds shifting to ENE at 10 to 15 mph."
I want the above string to read as below:
"Clear skies. Low 46 degrees. NNW winds shifting to ENE at 10 to 15 mph."
There could be more than one instance of a temperature in the string.
NOTE: I only want to remove the F or C if it's immediately following a number with no space in-between. If "Florida" were in the above string, I'd want the letter "F" left untouched.
I've tried the below regex, but it finds the entire 46F. I just want it changed to 46 degrees.
/\d+[FC]/g
Thanks.
That is because the lack of the capturing group (parentheses):
Use this:
/(\d+)[FC]/g
$1 means the first capturing group. The \d+ in this case.
speechOutput = speechOutput.replace(/(\d+)[FC]/g, '$1 degrees');
I've a struct array in which I store chapters title and other info after an OCR, at the end there's a GUI for manual adjustment in case of ocr failing.
All works fine but after an editing or if I reopen the GUI later from the command windows the strings are messed up, short strings have e blank space after every char, for example:
'first chapter' becomes 'f i r s t c h a p t e r'
while longer strings skip a row every character
'THIS IS AN EXAMPLE' becomes 'TE HX IA SM IP SL AE N'
I thought it was due to multiline strings but converting in a single line doesn't changed the results.
any ideas?
Thanks
I have a string variable with short text strings. I want to replace all the text strings with numbers based on key words contained inside the individual cells.
Example: Some cells states "I like cats", while others "I dont like the smell of wet dog".
I want to assign the value 1 to all cells containing the word cat, and the number 2 to all cells containing the word dog.
How do I do this?
This will put 1 in NewVar when "cat" appears in OldVar, 2 for "dog", 3 for "mouse":
do repeat wrd="cat" "dog" "mouse"/val= 1 2 3.
if index(OldVar, wrd)>0 NewVar=val.
end repeat.
This is only good if there will never be a cat AND a dog in the same sentence. If you do have such cases you should go this way:
do repeat wrd="cat" "dog" "mouse"/NewVar=cat dog mouse.
compute NewVar=char.index(OldVar, wrd)>0.
end repeat.
This will create a new variable for each of the possible words, putting 1 in cases where the word appears in OldVar, 0 when it doesn't.
Apparently you have to open a syntax window and enter this command:
COMPUTE newvar=CHAR.INDEX(UPCASE(VAR1),"ABCD")>0
newvar is the name of the new variable.
VAR1 is the name of the variable to be searched.
ABCD is the text to be searched for. NOTE: This must be in CAPITAL letters.
newvar will recieve a value of 1 if the text is found.
I'm in a basic MATLAB college course, and need some help with my code.
theres an external .txt file with names in it, with corresponding numbers assigned to each name. my goal is to place all the first names, last names, and numbers into arrays, find the lowest number in the 'number' array, get the corresponding indexer number, and print the first and last name related with that number.
the text file reads 25 different names and numbers
(i.e.:
Bob
Smith
17
Jane
Doe
23
Bill
Johnson
13
...etc...)
here is my general code so far:
1 clear
2
3 clc
4
5
6 fid1=fopen('facedata.txt','rt');
7
8 for index = 1:1:25
9 firstn(index) = fgetl(fid1);
10 lastn(index) = fgetl(fid1);
11 number(index) = fscanf(fid1,'%f');
12 end
13
14 [distmin,I] = min(dist);
15 fprintf('%5.4f %10s %10.0f', distmin, firstn(I), I);
My hope is for the code to run through, get matlab to recognize '13' as the lowest number, and print 'bill johnson' to the screen, but if I run the code, matlab says there are errors
Subscripted assignment dimension mismatch.' # line 9.
and
Index exceeds matrix dimensions.' # the firstn**(I)** in line 15.
any ideas?? i know this is crazy long, but any help would be appreciated! :]
The command fgetl means read a line from the text file. Therefore your code is reading 2x25 = 50 lines of text. How do you know that your file has this many lines in it? You should read a new line, process it, and repeat until you reach the end of the file:
fid = fopen('fgetl.m');
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);
However, this would not do what you want. You should rather use fscanf to read data in the format you want. You want to read two consecutive strings (first name, last name) and an integer number. So you can use
A = fscanf(fid, '%s %s %d', [3 inf]);
to read three items at a time and repeat until the end of the file.
I answered my own question earlier today, but here's what I found if anyone is interested:
you have to index a line of string by using curly brackets instead of straight ones.
i.e.:
for index = 1:1:25
firstname{index} = fgetl(fid1);
end
fprintf('%10s', firstn{index});
fprintf will print whichever number index is supplied.
thanks anyway kavka :]