excel:如何将单元格内容分解为代码

发布于 2024-09-24 05:27:47 字数 222 浏览 6 评论 0原文

有一个代码函数可以为每个字母返回 ASCII。

我想以一种将单元格 a1 = "some string" 分解

为 ASCII 代码的方式使用它:

像这样:“23423423434634

抱歉,我不知道确切的 ASCII,但你明白我的意思了。

请注意,我想专门使用公式而不是 VBA 来执行此操作

There is a code function that returns ASCII for every letter.

I would like to use it in a way that it will break up a cell a1 = "some string"

Into it's ASCII codes:

Something like this: "23423423434634"

Sorry I don't know the exact ASCII of that but you get my point.

please note that i would like to do this specifically with a formula and NOT with VBA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花期渐远 2024-10-01 05:27:47

一种方法是使用字节数组为每个字符提供 Unicode 数字对:

Sub ByteArray()
    Dim aByte() As Byte
    Dim str1 As String<
    Dim j As Long
    str1 = "ABC"
    aByte = str1
    For j = LBound(aByte) To UBound(aByte)
        MsgBox aByte(j)
    Next j
End Sub

One way is to use a Byte Array to give Unicode number pairs for each character:

Sub ByteArray()
    Dim aByte() As Byte
    Dim str1 As String<
    Dim j As Long
    str1 = "ABC"
    aByte = str1
    For j = LBound(aByte) To UBound(aByte)
        MsgBox aByte(j)
    Next j
End Sub
久而酒知 2024-10-01 05:27:47

编写 Excel 用户定义函数

该函数的伪代码如下:

string returnValue;
for each ( char c in string)
   returnValue = returnValue + Chr(char)
return returnValue

您可以调用 UDF 作为 Excel 公式的一部分,例如

=StringToASCIICodeValues(A1)

公式版本

您可以使用 Excel 内置公式手动执行此操作(Excel 没有公式的 for 循环函数

  1. A1="some string"
  2. A2="=MID($A$1,COLUMN(A2),1)"
  3. 将单元格 A2 中的公式拖到右侧。拖至 K2 以获取某些字符串示例。
  4. A3="=CODE(A2)"
  5. 将单元格 A3 中的公式拖到右侧。拖至 K3 以获取某些字符串示例。
  6. A4="=A3"
  7. B4="=CONCATENATE(A4,B3)"
  8. 将单元格 B4 中的公式拖到右侧。拖至单元格 K4 以获取某些字符串示例。
  9. 第 4 行具有值的最右边的列包含最终值。对于某些字符串,它将返回:单元格 K4 中的11511110910132115116114105110103

Write an Excel User Defined Function.

Pseudocode for the function is below:

string returnValue;
for each ( char c in string)
   returnValue = returnValue + Chr(char)
return returnValue

You can call the UDF as part of an excell formula eg

=StringToASCIICodeValues(A1)

Formula Version

You could do it manually with excel builtin formula's by (excel doesn't have a for-loop function for formulae)

  1. A1="some string"
  2. A2="=MID($A$1,COLUMN(A2),1)"
  3. Drag the formula in cell A2 to the right. Drag to K2 for some string example.
  4. A3="=CODE(A2)"
  5. Drag the formula in cell A3 to the right. Drag to K3 for some string example.
  6. A4="=A3"
  7. B4="=CONCATENATE(A4,B3)"
  8. Drag the formula in cell B4 to the right. Drag to Cell K4 for some string example.
  9. The right most column with a value on row 4 contains the final value. For some string it will return: 11511110910132115116114105110103 in cell K4
雨后咖啡店 2024-10-01 05:27:47
    string someText = "some string";
    CharEnumerator ce = someText.GetEnumerator();
    int counter = 0;
    while (ce.MoveNext())
    {
        char letter = someText[counter];
        //Call the function to get the ascii
        GetAsciiValue(letter);
        //Do something

        counter++;
    }

也许这可能对你有帮助。

问候, J'Sinh

    string someText = "some string";
    CharEnumerator ce = someText.GetEnumerator();
    int counter = 0;
    while (ce.MoveNext())
    {
        char letter = someText[counter];
        //Call the function to get the ascii
        GetAsciiValue(letter);
        //Do something

        counter++;
    }

May be this might help you.

Regards, J'Sinh

倾城花音 2024-10-01 05:27:47

虽然它很丑陋,但如果您的字符串不太长,您可以使用一个长公式来完成它,该公式转换每个字符,然后将它们重新连接在一起。

例如,此公式可以处理长度最多为 20 个字符的字符串(创建十六进制 ascii 代码):

=if(len(A1)>=1,DEC2HEX(CODE(MID(A1,1,1))),"")&
if(len(A1)>=2,DEC2HEX(CODE(MID(A1,2,1))),"")&
if(len(A1)>=3,DEC2HEX(CODE(MID(A1,3,1))),"")&
if(len(A1)>=4,DEC2HEX(CODE(MID(A1,4,1))),"")&
if(len(A1)>=5,DEC2HEX(CODE(MID(A1,5,1))),"")&
if(len(A1)>=6,DEC2HEX(CODE(MID(A1,6,1))),"")&
if(len(A1)>=7,DEC2HEX(CODE(MID(A1,7,1))),"")&
if(len(A1)>=8,DEC2HEX(CODE(MID(A1,8,1))),"")&
if(len(A1)>=9,DEC2HEX(CODE(MID(A1,9,1))),"")&
if(len(A1)>=10,DEC2HEX(CODE(MID(A1,10,1))),"")&
if(len(A1)>=11,DEC2HEX(CODE(MID(A1,11,1))),"")&
if(len(A1)>=12,DEC2HEX(CODE(MID(A1,12,1))),"")&
if(len(A1)>=13,DEC2HEX(CODE(MID(A1,13,1))),"")&
if(len(A1)>=14,DEC2HEX(CODE(MID(A1,14,1))),"")&
if(len(A1)>=15,DEC2HEX(CODE(MID(A1,15,1))),"")&
if(len(A1)>=16,DEC2HEX(CODE(MID(A1,16,1))),"")&
if(len(A1)>=17,DEC2HEX(CODE(MID(A1,17,1))),"")&
if(len(A1)>=18,DEC2HEX(CODE(MID(A1,18,1))),"")&
if(len(A1)>=19,DEC2HEX(CODE(MID(A1,19,1))),"")&
if(len(A1)>=20,DEC2HEX(CODE(MID(A1,20,1))),"")

对于较长的字符串,您可以重复此模式,尽管您会受到 Excel 允许的最大公式长度的限制,这似乎是 8,192 个字符< /a>.

Although it's ugly, if your strings are not too long you can do it with a long formula which converts each character and then joins them back together.

For example this formula can handle strings which are up to 20 characters in length (creating hex ascii codes):

=if(len(A1)>=1,DEC2HEX(CODE(MID(A1,1,1))),"")&
if(len(A1)>=2,DEC2HEX(CODE(MID(A1,2,1))),"")&
if(len(A1)>=3,DEC2HEX(CODE(MID(A1,3,1))),"")&
if(len(A1)>=4,DEC2HEX(CODE(MID(A1,4,1))),"")&
if(len(A1)>=5,DEC2HEX(CODE(MID(A1,5,1))),"")&
if(len(A1)>=6,DEC2HEX(CODE(MID(A1,6,1))),"")&
if(len(A1)>=7,DEC2HEX(CODE(MID(A1,7,1))),"")&
if(len(A1)>=8,DEC2HEX(CODE(MID(A1,8,1))),"")&
if(len(A1)>=9,DEC2HEX(CODE(MID(A1,9,1))),"")&
if(len(A1)>=10,DEC2HEX(CODE(MID(A1,10,1))),"")&
if(len(A1)>=11,DEC2HEX(CODE(MID(A1,11,1))),"")&
if(len(A1)>=12,DEC2HEX(CODE(MID(A1,12,1))),"")&
if(len(A1)>=13,DEC2HEX(CODE(MID(A1,13,1))),"")&
if(len(A1)>=14,DEC2HEX(CODE(MID(A1,14,1))),"")&
if(len(A1)>=15,DEC2HEX(CODE(MID(A1,15,1))),"")&
if(len(A1)>=16,DEC2HEX(CODE(MID(A1,16,1))),"")&
if(len(A1)>=17,DEC2HEX(CODE(MID(A1,17,1))),"")&
if(len(A1)>=18,DEC2HEX(CODE(MID(A1,18,1))),"")&
if(len(A1)>=19,DEC2HEX(CODE(MID(A1,19,1))),"")&
if(len(A1)>=20,DEC2HEX(CODE(MID(A1,20,1))),"")

For longer strings you could repeat this pattern, although you'd be limited by the maximum formula length allowed by Excel, which seems to be 8,192 characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文