从Fortran字符串中提取单个字符

从Fortran字符串中提取单个字符

本文介绍了从Fortran字符串中提取单个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个程序来将基数a转换为基数b,其中基数a和b可以从2到36.

I need a program to convert from base a to base b, where base a and b could be from 2 to 36.

我的想法是使用字符串作为数字,将其转换为以10为底的中介,然后从10以底转换为b.由于我是Fortran的新手,所以我不太了解函数和子字符串,现在我得到了错误:

My idea was to use strings as the numbers, convert to base 10 as an intermediary and then convert from base 10 to base b. As I'm new on Fortran I can't understand quite the functions and substring, right now I'm getting the error:

intToChar  = cadena(int,int)
1
Error: Unclassifiable statement at (1)

在下一个代码上:

CHARACTER FUNCTION intToChar(int)
    IMPLICIT NONE
    INTEGER, INTENT(IN) :: int
    CHARACTER(LEN = 36) :: cadena

    cadena = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    intToChar    = cadena(int,int)
END FUNCTION intToChar

我正在关注教程

推荐答案

从字符变量中选择子字符串的语法使用冒号:,而不是逗号,.编译器抱怨的行应该是:

The syntax to select a substring from a character variable uses a colon :, not a comma ,. The line the compiler is complaining about should be:

intToChar = cadena(int:int)

这将从cadena中选择单个字符作为位置int,这似乎是您使用该功能的目标.

This will select the single character as position int from cadena, which appears to be your goal with that function.

这篇关于从Fortran字符串中提取单个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:08