字符串在vbscript中按字母顺序排序

编程入门 行业动态 更新时间:2024-10-11 19:20:30
本文介绍了字符串在vbscript中按字母顺序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

i有一个问题,假设我的字符串包含cdaf,我想按字母顺序输出acdf,任何人都可以在vbscript中提供代码。提前谢谢 我的尝试:

Hi, i have a question suppose my string contains "cdaf" and i want the out in alphabetical order like "acdf" can any one give me the code in vbscript.Thanks in advance What I have tried:

Dim str str="edfca" strlength= len(str) MsgBox strlength For i=0 to strlength For j=0 to strlength-1 If j > i Then TempValue = j i = j j = TempValue End If

推荐答案

从代码的外观来看,你正在尝试气泡排序 [ ^ ] 要做的第一件事就是把你的字符串变成一个字符数组 - 你并没有严格地说有来做这个,但是它会使其余的代码更容易阅读。这样的事情: From the look of your code you are attempting a Bubble Sort[^] The first thing to do is to get your string into a character array - you don't strictly speaking have to do this but it will make the rest of the code easier to read. Something like this: ReDim chars(strlength - 1) As String For i = 1 To strlength chars(i - 1) = Mid

(str,i, 1 ) 下一步 (str, i, 1) Next

之后,您的尝试距离标记不太远,除非您需要要查看和交换实际字符而不是循环计数器。 例如

After that, your attempt isn't too far off the mark, except you need to be looking at and swapping the actual characters not the loop counters. E.g.

If chars(i) > chars(j) Then TempValue = chars(j) etc...

因为这显然是家庭作业我不会给你完整的代码 - 给自己一个额外的信息......但我会给你一个提示:

As this is obviously homework I'm not going to give you the full code - give it a go yourself with this extra information ... but I'll give you one hint:

For j=0 to strlength-1

... 0表示不正确。查看我给你的链接上的文档,看看它应该是什么。

...that 0 is incorrect. Check the documentation on the link I gave you to see what it should be.

更多推荐

字符串在vbscript中按字母顺序排序

本文发布于:2023-11-10 14:22:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   字母   顺序   vbscript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!