小编Ros*_*nck的帖子

如何在两个字符之间获取字符串?

我有一个字符串,

String s = "test string (67)";
Run Code Online (Sandbox Code Playgroud)

我想得到no 67,这是(和)之间的字符串.

谁能告诉我怎么做?

java string

70
推荐指数
12
解决办法
19万
查看次数

如何从JMockit模拟静态方法

我有一个静态方法,它将从类中的测试方法调用,如下所示

public class MyClass
{
   private static boolean mockMethod( String input )
    {
       boolean value;
       //do something to value
       return value; 
    }

    public static boolean methodToTest()
    {
       boolean getVal = mockMethod( "input" );
       //do something to getVal
       return getVal; 
    }
}
Run Code Online (Sandbox Code Playgroud)

我想通过模拟mockMethod为方法methodToTest编写一个测试用例.试图吼叫,它没有任何输出

@Before
public void init()
{
    Mockit.setUpMock( MyClass.class, MyClassMocked.class );
}

public static class MyClassMocked extends MockUp<MyClass>
{
    @Mock
    private static boolean mockMethod( String input )
    {
        return true;
    }
}

@Test
public void testMethodToTest() …
Run Code Online (Sandbox Code Playgroud)

java testing unit-testing jmockit

19
推荐指数
3
解决办法
4万
查看次数

如何在脚本标记内设置变量

我有一个页面名称index.php.我在页面顶部有一个脚本变量如下:

<script>
    var search_quarry = "some_test";
</script>
Run Code Online (Sandbox Code Playgroud)

在同一页面的底部,我想将此变量添加到src脚本标记的属性中:

<script src=NEED_TO_ADD_HERE></script>
Run Code Online (Sandbox Code Playgroud)

这不起作用:

<script src=search_quarry> </script>
Run Code Online (Sandbox Code Playgroud)

谁能告诉我怎么做?

html javascript javascript-events

5
推荐指数
1
解决办法
2万
查看次数

Microsoft Graph API Authentication_MissingOrMalformed

我正在使用oauth2 / token验证我的应用程序并获取access_token。贝娄是运行良好的Java代码。

    private String getToken() throws Exception {
        String access_token = "";
        String url = "https://login.windows.net/MyApplication_ID_here/oauth2/token";
        HttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);

        post.setHeader("Content-Type", "application/x-www-form-urlencoded");

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("grant_type", "client_credentials"));
        urlParameters.add(new BasicNameValuePair("client_id", "MyApplication_ID_here"));
        urlParameters.add(new BasicNameValuePair("client_secret", "MyApplication_secret_here"));
        urlParameters.add(new BasicNameValuePair("resource", "https://graph.microsoft.com"));

        post.setEntity(new UrlEncodedFormEntity(urlParameters));

        HttpResponse response = client.execute(post);
        System.out.println("Sending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + post.getEntity());
        System.out.println("Response Code : " + response.getStatusLine().getStatusCode());

        String responseAsString = EntityUtils.toString(response.getEntity());
        System.out.println(responseAsString);
        try …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 office365 azure-active-directory azure-ad-graph-api microsoft-graph

4
推荐指数
1
解决办法
3024
查看次数

如何使用html文件选择器将照片上传到facebook(graph api)(输入类型="文件")

我有一个html文件,从用户的computer.code中选择图像

  <html>
    <body>
    <form enctype="multipart/form-data" action="http://localhost/uploader/upload.php" method="POST">
    Please choose a photo: 
    <input name="source" type="file"><br/><br/>
    Say something about this photo: 
    <input name="message" type="text" value=""><br/><br/>
    <input type="submit" value="Upload"/><br/>
    </form>
    </body>  
 </html>
Run Code Online (Sandbox Code Playgroud)

当我按上传按钮时,我需要将所选图像的真实路径传递给upload.php的upload.php文件.

<?php
    include_once 'fbmain.php';
    //some codes 
    try{
    $uid = $facebook->getUser();
        $me = $facebook->api('/me');
        $token = $session['access_token'];//here I get the token from the $session array
        $album_id = '2179901265385';//MY ALBUM ID

        //upload my photo
        $FILE_PATH= 'HERE_I_NEED_THE_REAL_PATH_OF_THE_IMAGE';
        $facebook->setFileUploadSupport(true);
        $args = array('message' => 'Photo Caption');
        $args['image'] = '@' . realpath($FILE_PATH);

        $data = $facebook->api('/'. $album_id . …
Run Code Online (Sandbox Code Playgroud)

html php facebook html-input facebook-graph-api

3
推荐指数
1
解决办法
3753
查看次数

如何从字符串中删除特定的特殊字符模式

我有一个字符串名称s,

String s = "<NOUN>Sam</NOUN> , a student of the University of oxford , won the Ethugalpura International Rating Chess Tournament which concluded on Dec.22 at the Blue Olympiad Hotel";  
Run Code Online (Sandbox Code Playgroud)

我想从字符串中删除所有< NOUN >和< / NOUN >标记.我用它来删除标签,

s.replaceAll("[<NOUN>,</NOUN>]","");
Run Code Online (Sandbox Code Playgroud)

是的,它删除了标签.但它也会从字符串中删除字母"U"和"O"字符,这会给我以下输出.

 Sam , a student of the niversity of oxford , won the Ethugalpura International Rating Chess Tournament which concluded on Dec.22 at the Blue lympiad Hotel
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何正确地做到这一点?

java string

2
推荐指数
1
解决办法
1万
查看次数

如何从插入到hashmap中的顺序打印hashmap值

我有一个HashMap,它有字符串作为键和值,

HashMap dataSet = new HashMap();

dataSet.put("A1", "Aania");
dataSet.put("X1", "Abatha");
dataSet.put("C1", "Acathan");
dataSet.put("S1", "Adreenas");
Run Code Online (Sandbox Code Playgroud)

我想打印它作为插入HashMap的顺序,所以输出应该像,

A1, Aania
X1, Abatha
C1, Acathan
S1, Adreenas  
Run Code Online (Sandbox Code Playgroud)

谁能告诉我怎么做?

java string hashmap

2
推荐指数
1
解决办法
3260
查看次数

如何将图像 url 提供给 createImageInputStream 方法

我有一个图片网址,例如

String url = "http://XXXXXXX/img_High-Octane-Sauce-Company-JP5-400x1024.jpg";
Run Code Online (Sandbox Code Playgroud)

我需要将其作为该方法的输入,

ImageInputStream in = ImageIO.createImageInputStream( urlInputHere );
Run Code Online (Sandbox Code Playgroud)

所以我可以在不使用图像缓冲区的情况下读取图像的宽度和高度。谁能告诉我如何做到这一点?

这是我阅读图像的方式

ImageInputStream in = ImageIO.createImageInputStream(resourceFile);
try {
    final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
    if (readers.hasNext()) {
        ImageReader reader = readers.next();
        try {
            reader.setInput(in);
            return new Dimension(reader.getWidth(0), reader.getHeight(0));
        } finally {
            reader.dispose();
        }
    }
} finally {
    if (in != null) in.close();
}
Run Code Online (Sandbox Code Playgroud)

PS 取自:Java/ImageIO 在不读取整个文件的情况下获取图像尺寸?

java image objectinputstream

2
推荐指数
1
解决办法
1189
查看次数

删除特殊字符前后的空格

我有一个字符串,

String sample = "He won the International Rating Chess Tournament (IRCT ) which concluded on Dec. 22 at the Blue Sky Hotel , Canada";
Run Code Online (Sandbox Code Playgroud)

我想删除字符')'和','之前留下的空格(如果有的话).所以最终输出应该是,

He won the International Rating Chess Tournament (IRCT) which concluded on Dec. 22 at the Blue Sky Hotel, Canada
Run Code Online (Sandbox Code Playgroud)

谁能告诉我怎么做?

java string

0
推荐指数
1
解决办法
5418
查看次数