A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
1
Task/Increment-a-numerical-string/0DESCRIPTION
Normal file
1
Task/Increment-a-numerical-string/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
This task is about incrementing a numerical string.
|
||||
2
Task/Increment-a-numerical-string/1META.yaml
Normal file
2
Task/Increment-a-numerical-string/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Text processing
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
report zz_incstring
|
||||
perform test using: '0', '1', '-1', '10000000', '-10000000'.
|
||||
|
||||
form test using iv_string type string.
|
||||
data: lv_int type i,
|
||||
lv_string type string.
|
||||
lv_int = iv_string + 1.
|
||||
lv_string = lv_int.
|
||||
concatenate '"' iv_string '" + 1 = "' lv_string '"' into lv_string.
|
||||
write / lv_string.
|
||||
endform.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
STRING s := "12345"; FILE f; INT i;
|
||||
associate(f, s); get(f,i);
|
||||
i+:=1;
|
||||
s:=""; reset(f); put(f,i);
|
||||
print((s, new line))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ awk 'BEGIN{s="42";s++;print s"("length(s)")"}'
|
||||
43(2)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function incrementString(str:String):String
|
||||
{
|
||||
return String(Number(str)+1);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
S : String := "12345";
|
||||
S := Ada.Strings.Fixed.Trim(Source => Integer'Image(Integer'Value(S) + 1), Side => Ada.Strings.Both);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
o_text(itoa(atoi("2047") + 1));
|
||||
o_byte('\n');
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
str = 12345
|
||||
MsgBox % str += 1
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Global $x = "12345"
|
||||
$x += 1
|
||||
MsgBox(0,"",$x)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
s$ = "12345"
|
||||
s$ = STR$(VAL(s$) + 1)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
10 LET s$ = "12345"
|
||||
20 LET s$ = STR$(VAL(s$) + 1)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
num$ = "567"
|
||||
REPEAT
|
||||
PRINT num$
|
||||
PROCinc$(num$)
|
||||
UNTIL FALSE
|
||||
END
|
||||
|
||||
DEF PROCinc$(RETURN n$)
|
||||
LOCAL A$, I%
|
||||
I% = LEN(n$)
|
||||
REPEAT
|
||||
A$ = CHR$(ASCMID$(n$,I%) + 1)
|
||||
IF A$=":" A$ = "0"
|
||||
MID$(n$,I%,1) = A$
|
||||
I% -= 1
|
||||
UNTIL A$<>"0" OR I%=0
|
||||
IF A$="0" n$ = "1" + n$
|
||||
ENDPROC
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
set s=12345
|
||||
set /a s+=1
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
s = "1234"
|
||||
s = (int.Parse(s) + 1).ToString()
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(n=35664871829866234762187538073934873121878/6172839450617283945)
|
||||
&!n+1:?n
|
||||
&out$!n
|
||||
|
||||
35664871829866234762193710913385490405823/6172839450617283945
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
#Convert to integer, increment, then back to string
|
||||
p ("100".to_i + 1).to_s #Prints 101
|
||||
|
|
@ -0,0 +1 @@
|
|||
ri?ish
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// standard C++ string stream operators
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
// inside a function or method...
|
||||
std::string s = "12345";
|
||||
|
||||
int i;
|
||||
std::istringstream(s) >> i;
|
||||
i++;
|
||||
//or:
|
||||
//int i = std::atoi(s.c_str()) + 1;
|
||||
|
||||
std::ostringstream oss;
|
||||
if (oss << i) s = oss.str();
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#include <string>
|
||||
|
||||
std::string s = "12345";
|
||||
s = std::to_string(1+std::stoi(s));
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// Boost
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
// inside a function or method...
|
||||
std::string s = "12345";
|
||||
int i = boost::lexical_cast<int>(s) + 1;
|
||||
s = boost::lexical_cast<std::string>(i);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Qt
|
||||
QString num1 = "12345";
|
||||
QString num2 = QString("%1").arg(v1.toInt()+1);
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
// MFC
|
||||
CString s = "12345";
|
||||
int i = _ttoi(s) + 1;
|
||||
int i = _tcstoul(s, NULL, 10) + 1;
|
||||
s.Format("%d", i);
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
void increment_numerical_string(std::string& s)
|
||||
{
|
||||
std::string::reverse_iterator iter = s.rbegin(), end = s.rend();
|
||||
int carry = 1;
|
||||
while (carry && iter != end)
|
||||
{
|
||||
int value = (*iter - '0') + carry;
|
||||
carry = (value / 10);
|
||||
*iter = '0' + (value % 10);
|
||||
++iter;
|
||||
}
|
||||
if (carry)
|
||||
s.insert(0, "1");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string big_number = "123456789012345678901234567899";
|
||||
std::cout << "before increment: " << big_number << "\n";
|
||||
increment_numerical_string(big_number);
|
||||
std::cout << "after increment: " << big_number << "\n";
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Constraints: input is in the form of (\+|-)?[0-9]+
|
||||
* and without leading zero (0 itself can be as "0" or "+0", but not "-0");
|
||||
* input pointer is realloc'able and may change;
|
||||
* if input has leading + sign, return may or may not keep it.
|
||||
* The constranits conform to sprintf("%+d") and this function's own output.
|
||||
*/
|
||||
char * incr(char *s)
|
||||
{
|
||||
int i, begin, tail, len;
|
||||
int neg = (*s == '-');
|
||||
char tgt = neg ? '0' : '9';
|
||||
|
||||
/* special case: "-1" */
|
||||
if (!strcmp(s, "-1")) {
|
||||
s[0] = '0', s[1] = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
len = strlen(s);
|
||||
begin = (*s == '-' || *s == '+') ? 1 : 0;
|
||||
|
||||
/* find out how many digits need to be changed */
|
||||
for (tail = len - 1; tail >= begin && s[tail] == tgt; tail--);
|
||||
|
||||
if (tail < begin && !neg) {
|
||||
/* special case: all 9s, string will grow */
|
||||
if (!begin) s = realloc(s, len + 2);
|
||||
s[0] = '1';
|
||||
for (i = 1; i <= len - begin; i++) s[i] = '0';
|
||||
s[len + 1] = '\0';
|
||||
} else if (tail == begin && neg && s[1] == '1') {
|
||||
/* special case: -1000..., so string will shrink */
|
||||
for (i = 1; i < len - begin; i++) s[i] = '9';
|
||||
s[len - 1] = '\0';
|
||||
} else { /* normal case; change tail to all 0 or 9, change prev digit by 1*/
|
||||
for (i = len - 1; i > tail; i--)
|
||||
s[i] = neg ? '9' : '0';
|
||||
s[tail] += neg ? -1 : 1;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void string_test(const char *s)
|
||||
{
|
||||
char *ret = malloc(strlen(s));
|
||||
strcpy(ret, s);
|
||||
|
||||
printf("text: %s\n", ret);
|
||||
printf(" ->: %s\n", ret = incr(ret));
|
||||
free(ret);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
string_test("+0");
|
||||
string_test("-1");
|
||||
string_test("-41");
|
||||
string_test("+41");
|
||||
string_test("999");
|
||||
string_test("+999");
|
||||
string_test("109999999999999999999999999999999999999999");
|
||||
string_test("-100000000000000000000000000000000000000000000");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
text: +0
|
||||
->: +1
|
||||
text: -1
|
||||
->: 0
|
||||
text: -41
|
||||
->: -40
|
||||
text: +41
|
||||
->: +42
|
||||
text: 999
|
||||
->: 1000
|
||||
text: +999
|
||||
->: 1000
|
||||
text: 109999999999999999999999999999999999999999
|
||||
->: 110000000000000000000000000000000000000000
|
||||
text: -100000000000000000000000000000000000000000000
|
||||
->: -99999999999999999999999999999999999999999999
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
set(string "1599")
|
||||
math(EXPR string "${string} + 1")
|
||||
message(STATUS "${string}")
|
||||
|
|
@ -0,0 +1 @@
|
|||
(str (inc (Integer/parseInt "1234")))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(princ-to-string (1+ (parse-integer "1234")))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import std.string;
|
||||
|
||||
void main() {
|
||||
string s = succ("12345");
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var value : String = "1234";
|
||||
value := IntToStr(StrToInt(value) + 1);
|
||||
PrintLn(value);
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
program IncrementNumericalString;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses SysUtils;
|
||||
|
||||
const
|
||||
STRING_VALUE = '12345';
|
||||
begin
|
||||
WriteLn(Format('"%s" + 1 = %d', [STRING_VALUE, StrToInt(STRING_VALUE) + 1]));
|
||||
|
||||
Readln;
|
||||
end.
|
||||
|
|
@ -0,0 +1 @@
|
|||
__makeInt("1234", 10).next().toString(10)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
s string = "12345";
|
||||
s = 1 + s; // Note: s + 1 is a string concatenation.
|
||||
|
|
@ -0,0 +1 @@
|
|||
(1+ (string-to-number "12345"))
|
||||
|
|
@ -0,0 +1 @@
|
|||
integer_to_list(list_to_integer("1336")+1).
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
include get.e
|
||||
|
||||
function val(sequence s)
|
||||
sequence x
|
||||
x = value(s)
|
||||
return x[2]
|
||||
end function
|
||||
|
||||
sequence s
|
||||
|
||||
s = "12345"
|
||||
s = sprintf("%d",{val(s)+1})
|
||||
|
|
@ -0,0 +1 @@
|
|||
"1234" string>number 1 + number>string
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
fansh> a := "123"
|
||||
123
|
||||
fansh> (a.toInt + 1).toStr
|
||||
124
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
: >string ( d -- addr n )
|
||||
dup >r dabs <# #s r> sign #> ;
|
||||
|
||||
: inc-string ( addr -- )
|
||||
dup count number? not abort" invalid number"
|
||||
1 s>d d+ >string rot place ;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
: inc-string ( addr n -- )
|
||||
over count number? not abort" invalid number"
|
||||
rot s>d d+ >string rot place ;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
s" 123" pad place
|
||||
pad inc-string
|
||||
pad count type
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
s" 123" pad place
|
||||
pad 1 inc-string
|
||||
pad count type
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
CHARACTER(10) :: intstr = "12345", realstr = "1234.5"
|
||||
INTEGER :: i
|
||||
REAL :: r
|
||||
|
||||
READ(intstr, "(I10)") i ! Read numeric string into integer i
|
||||
i = i + 1 ! increment i
|
||||
WRITE(intstr, "(I10)") i ! Write i back to string
|
||||
|
||||
READ(realstr, "(F10.1)") r
|
||||
r = r + 1.0
|
||||
WRITE(realstr, "(F10.1)") r
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# Using built-in functions
|
||||
Incr := s -> String(Int(s) + 1);
|
||||
|
||||
# Implementing addition
|
||||
# (but here 9...9 + 1 = 0...0 since the string length is fixed)
|
||||
Increment := function(s)
|
||||
local c, n, carry, digits;
|
||||
digits := "0123456789";
|
||||
n := Length(s);
|
||||
carry := true;
|
||||
while n > 0 and carry do
|
||||
c := Position(digits, s[n]) - 1;
|
||||
if carry then
|
||||
c := c + 1;
|
||||
fi;
|
||||
if c > 9 then
|
||||
carry := true;
|
||||
c := c - 10;
|
||||
else
|
||||
carry := false;
|
||||
fi;
|
||||
s[n] := digits[c + 1];
|
||||
n := n - 1;
|
||||
od;
|
||||
end;
|
||||
|
||||
s := "2399";
|
||||
Increment(s);
|
||||
s;
|
||||
# "2400"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
import "fmt"
|
||||
import "strconv"
|
||||
func main() {
|
||||
i, _ := strconv.Atoi("1234")
|
||||
fmt.Println(strconv.Itoa(i + 1))
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"big"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// integer
|
||||
is := "1234"
|
||||
fmt.Println("original: ", is)
|
||||
i, err := strconv.Atoi(is)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// assignment back to original variable shows result is the same type.
|
||||
is = strconv.Itoa(i + 1)
|
||||
fmt.Println("incremented:", is)
|
||||
|
||||
// error checking worthwhile
|
||||
fmt.Println()
|
||||
_, err = strconv.Atoi(" 1234") // whitespace not allowed
|
||||
fmt.Println(err)
|
||||
_, err = strconv.Atoi("12345678901")
|
||||
fmt.Println(err)
|
||||
_, err = strconv.Atoi("_1234")
|
||||
fmt.Println(err)
|
||||
_, err = strconv.Atof64("12.D34")
|
||||
fmt.Println(err)
|
||||
|
||||
// float
|
||||
fmt.Println()
|
||||
fs := "12.34"
|
||||
fmt.Println("original: ", fs)
|
||||
f, err := strconv.Atof64(fs)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// various options on Ftoa64 produce different formats. All are valid
|
||||
// input to Atof64, so result format does not have to match original
|
||||
// format. (Matching original format would take a lot of code.)
|
||||
fs = strconv.Ftoa64(f+1, 'g', -1)
|
||||
fmt.Println("incremented:", fs)
|
||||
fs = strconv.Ftoa64(f+1, 'e', 4)
|
||||
fmt.Println("what format?", fs)
|
||||
|
||||
// complex
|
||||
// strconv package doesn't handle complex types, but fmt does.
|
||||
// (fmt can be used on ints and floats too, but strconv is more efficient.)
|
||||
fmt.Println()
|
||||
cs := "(12+34i)"
|
||||
fmt.Println("original: ", cs)
|
||||
var c complex128
|
||||
_, err = fmt.Sscan(cs, &c)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
cs = fmt.Sprint(c + 1)
|
||||
fmt.Println("incremented:", cs)
|
||||
|
||||
// big integers have their own functions
|
||||
fmt.Println()
|
||||
bs := "170141183460469231731687303715884105728"
|
||||
fmt.Println("original: ", bs)
|
||||
var b, one big.Int
|
||||
_, ok := b.SetString(bs, 10)
|
||||
if !ok {
|
||||
fmt.Println("big.SetString fail")
|
||||
return
|
||||
}
|
||||
one.SetInt64(1)
|
||||
bs = b.Add(&b, &one).String()
|
||||
fmt.Println("incremented:", bs)
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
~)`
|
||||
|
|
@ -0,0 +1 @@
|
|||
"1234" ~)` p
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
println ((("23455" as BigDecimal) + 1) as String)
|
||||
println ((("23455.78" as BigDecimal) + 1) as String)
|
||||
|
|
@ -0,0 +1 @@
|
|||
((show :: Integer -> String) . succ . read) "1234"
|
||||
|
|
@ -0,0 +1 @@
|
|||
((show :: Bool -> String) . succ . read) "False"
|
||||
|
|
@ -0,0 +1 @@
|
|||
(show . (+1) . read) "1234"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
CHARACTER string = "123 -4567.89"
|
||||
|
||||
READ( Text=string) a, b
|
||||
WRITE(Text=string) a+1, b+1 ! 124 -4566.89
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
str = '1234'
|
||||
print, string(fix(str)+1)
|
||||
;==> 1235
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
print, '1234' + 1
|
||||
;==> 1235
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
s := "123" # s is a string
|
||||
s +:= 1# s is now an integer
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Home is a room.
|
||||
|
||||
To decide which indexed text is incremented (T - indexed text):
|
||||
let temp be indexed text;
|
||||
let temp be the player's command;
|
||||
change the text of the player's command to T;
|
||||
let N be a number;
|
||||
if the player's command matches "[number]":
|
||||
let N be the number understood;
|
||||
change the text of the player's command to temp;
|
||||
decide on "[N + 1]".
|
||||
|
||||
When play begins:
|
||||
say incremented "12345";
|
||||
end the story.
|
||||
|
|
@ -0,0 +1 @@
|
|||
incrTextNum=: >:&.".
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
incrTextNum '34.5'
|
||||
35.5
|
||||
incrTextNum '7 0.2 3r5 2j4 5.7e_4'
|
||||
8 1.2 1.6 3j4 1.00057
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
|.incrTextNum'123 456'
|
||||
754 421
|
||||
|.1+123 456
|
||||
457 124
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
String s = "12345";
|
||||
s = String.valueOf(Integer.parseInt(s) + 1);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
String s = "123456789012345678901234567890.12345";
|
||||
s = new BigDecimal(s).add(BigDecimal.ONE).toString();
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
var s = "12345";
|
||||
s = (Number(s) + 1).toString();
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
1 + ."1234"
|
||||
1235
|
||||
1 + ."1234.56"
|
||||
1235.56
|
||||
|
||||
/ As a function
|
||||
inc:{1 + . x}
|
||||
inc "1234"
|
||||
1235
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
1 + .:' ("1";"2";"3";"4")
|
||||
2 3 4 5
|
||||
|
||||
1 + . "123 456"
|
||||
124 457
|
||||
|
||||
. "1","+","-10"
|
||||
-9
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
HAI 1.3
|
||||
|
||||
I HAS A foo ITZ "1234"
|
||||
foo R SUM OF foo AN 1
|
||||
VISIBLE foo BTW, prints 1235
|
||||
|
||||
KTHXBYE
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
default {
|
||||
state_entry() {
|
||||
llListen(PUBLIC_CHANNEL, "", llGetOwner(), "");
|
||||
llOwnerSay("Say a Number and I'll Increment it.");
|
||||
}
|
||||
listen(integer iChannel, string sName, key kId, string sMessage) {
|
||||
llOwnerSay("You said '"+sMessage+"' + 1 = "+(string)(((integer)sMessage)+1));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
\documentclass{article}
|
||||
|
||||
% numbers are stored in counters
|
||||
\newcounter{tmpnum}
|
||||
|
||||
% macro to increment a string (given as argument)
|
||||
\newcommand{\stringinc}[1]{%
|
||||
\setcounter{tmpnum}{#1}% setcounter effectively converts the string to a number
|
||||
\stepcounter{tmpnum}% increment the counter; alternatively: \addtocounter{tmpnum}{1}
|
||||
\arabic{tmpnum}% convert counter value to arabic (i.e. decimal) number string
|
||||
}
|
||||
|
||||
%example usage
|
||||
\begin{document}
|
||||
The number 12345 is followed by \stringinc{12345}.
|
||||
\end{document}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
' [RC] Increment a numerical string.
|
||||
|
||||
o$ ="12345"
|
||||
print o$
|
||||
|
||||
v =val( o$)
|
||||
o$ =str$( v +1)
|
||||
print o$
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
show "123 + 1 ; 124
|
||||
show word? ("123 + 1) ; true
|
||||
|
|
@ -0,0 +1 @@
|
|||
number_chars(Number, "123"), Number2 is Number+1, number_chars(Number2, String2)
|
||||
|
|
@ -0,0 +1 @@
|
|||
print(tonumber("2345")+1)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
define(`V',`123')dnl
|
||||
define(`VN',`-123')dnl
|
||||
eval(V+1)
|
||||
eval(VN+1)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function numStr = incrementNumStr(numStr)
|
||||
numStr = num2str(str2double(numStr) + 1);
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
str = "12345"
|
||||
str = ((str as integer) + 1) as string
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
SET STR="123"
|
||||
WRITE STR+1
|
||||
|
|
@ -0,0 +1 @@
|
|||
Print[FromDigits["1234"] + 1]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
string s;
|
||||
s := "1234";
|
||||
s := decimal(scantokens(s)+1);
|
||||
message s;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
MODULE addstr;
|
||||
|
||||
IMPORT InOut, NumConv, Strings;
|
||||
|
||||
VAR str1, str2 : Strings.String;
|
||||
num : CARDINAL;
|
||||
ok : BOOLEAN;
|
||||
|
||||
BEGIN
|
||||
str1 := "12345";
|
||||
InOut.Write ('"'); InOut.WriteString (str1); InOut.WriteString ('" + 1 = ');
|
||||
NumConv.Str2Num (num, 10, str1, ok);
|
||||
INC (num);
|
||||
NumConv.Num2Str (num, 10, str2, ok);
|
||||
InOut.WriteString (str2);
|
||||
InOut.WriteLn
|
||||
END addstr.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
MODULE StringInt EXPORTS Main;
|
||||
|
||||
IMPORT IO, Fmt, Scan;
|
||||
|
||||
VAR string: TEXT := "1234";
|
||||
num: INTEGER := 0;
|
||||
|
||||
BEGIN
|
||||
num := Scan.Int(string);
|
||||
IO.Put(string & " + 1 = " & Fmt.Int(num + 1) & "\n");
|
||||
END StringInt.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$s = "12345";
|
||||
$s++;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
my $s = "12345";
|
||||
$s++;
|
||||
|
|
@ -0,0 +1 @@
|
|||
(format (inc (format "123456")))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
incr_numerical_string(S1, S2) :-
|
||||
string_to_atom(S1, A1),
|
||||
atom_number(A1, N1),
|
||||
N2 is N1+1,
|
||||
atom_number(A2, N2),
|
||||
string_to_atom(S2, A2).
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
?- incr_numerical_string("123", S2).
|
||||
S2 = "124".
|
||||
|
|
@ -0,0 +1 @@
|
|||
next = str(int('123') + 1)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
s = "12345"
|
||||
s <- as.character(as.numeric(s) + 1)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
count = "3" /*typeless variables are all character strings.*/
|
||||
count = 3 /*(same as above)*/
|
||||
count = count + 1 /*variables in a numerical context are treated as numbers.*/
|
||||
say count
|
||||
|
||||
/*------------------ The default numeric digits for REXX is 9 digits. */
|
||||
/*------------------ However, that can be increased with NUMERIC DIGITS.*/
|
||||
|
||||
numeric digits 15000 /*let's go ka-razy with fifteen thousand digits. */
|
||||
|
||||
count=copies(2,15000) /*stressing REXX's brains with lots of two's, */
|
||||
/*the above is considered a number in REXX. */
|
||||
count=count+3 /*make that last digit a "five". */
|
||||
|
||||
say 'count=' count /*ya most likely don't want to display this thing*/
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/* REXX ************************************************************
|
||||
* 11.12.2012 Walter Pachl
|
||||
* There is no equivalent to PL/I's SIZE condition in REXX.
|
||||
* The result of an arithmetic expression is rounded
|
||||
* according to the current setting of Numeric Digits.
|
||||
* ooRexx introduced, however, a LOSTDIGITS condition that checks
|
||||
* if any of the OPERANDS exceeds this number of digits.
|
||||
* Unfortunately this check is currently a little too weak
|
||||
* and will not recognise a 10-digit number to be too large.
|
||||
* This little bug will be fixed in the next release of ooRexx.
|
||||
**********************************************************************/
|
||||
Parse Version v .
|
||||
Say v
|
||||
z=999999998
|
||||
Do i=1 To 3
|
||||
z=z+1
|
||||
Say z
|
||||
End
|
||||
Numeric Digits 20
|
||||
z=999999998
|
||||
Do i=1 To 3
|
||||
z=z+1
|
||||
Say z
|
||||
End
|
||||
Numeric Digits 9
|
||||
If left(v,11)='REXX-ooRexx' Then
|
||||
Signal On Lostdigits
|
||||
z=100000000012
|
||||
Say z
|
||||
z=z+1
|
||||
Say z
|
||||
Exit
|
||||
lostdigits:
|
||||
Say 'LOSTDIGITS condition raised in line' sigl
|
||||
Say 'sourceline='sourceline(sigl)
|
||||
Say "condition('D')="condition('D')
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
#lang racket
|
||||
(define next (compose number->string add1 string->number))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
'1234'.succ #=> '1235'
|
||||
'99'.succ #=> '100'
|
||||
|
|
@ -0,0 +1 @@
|
|||
implicit def toSucc(s: String) = new { def succ = BigDecimal(s) + 1 toString }
|
||||
|
|
@ -0,0 +1 @@
|
|||
(number->string (+ 1 (string->number "1234")))
|
||||
|
|
@ -0,0 +1 @@
|
|||
('123' asInteger + 1) printString
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
set str 1234
|
||||
incr str
|
||||
Loading…
Add table
Add a link
Reference in a new issue